| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; |
| 11 import 'package:analyzer/dart/element/type.dart'; |
| 12 import 'package:analyzer/error/error.dart'; |
| 7 import 'package:analyzer/src/context/cache.dart'; | 13 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/dart/element/element.dart'; |
| 15 import 'package:analyzer/src/error/codes.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 16 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | |
| 11 import 'package:analyzer/src/generated/engine.dart' | 17 import 'package:analyzer/src/generated/engine.dart' |
| 12 show AnalysisOptionsImpl, CacheState; | 18 show AnalysisOptionsImpl, CacheState; |
| 13 import 'package:analyzer/src/generated/error.dart'; | |
| 14 import 'package:analyzer/src/generated/resolver.dart'; | 19 import 'package:analyzer/src/generated/resolver.dart'; |
| 15 import 'package:analyzer/src/generated/scanner.dart'; | |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | 20 import 'package:analyzer/src/generated/sdk.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/services/lint.dart'; | 22 import 'package:analyzer/src/services/lint.dart'; |
| 19 import 'package:analyzer/src/task/dart.dart'; | 23 import 'package:analyzer/src/task/dart.dart'; |
| 20 import 'package:analyzer/src/task/html.dart'; | 24 import 'package:analyzer/src/task/html.dart'; |
| 21 import 'package:analyzer/src/task/strong/info.dart'; | 25 import 'package:analyzer/src/task/strong/ast_properties.dart' as strong_ast; |
| 22 import 'package:analyzer/task/dart.dart'; | 26 import 'package:analyzer/task/dart.dart'; |
| 23 import 'package:analyzer/task/general.dart'; | 27 import 'package:analyzer/task/general.dart'; |
| 24 import 'package:analyzer/task/model.dart'; | 28 import 'package:analyzer/task/model.dart'; |
| 29 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 25 import 'package:unittest/unittest.dart'; | 30 import 'package:unittest/unittest.dart'; |
| 26 | 31 |
| 27 import '../../generated/resolver_test.dart'; | 32 import '../../generated/resolver_test_case.dart'; |
| 28 import '../../generated/test_support.dart'; | 33 import '../../generated/test_support.dart'; |
| 29 import '../../reflective_tests.dart'; | |
| 30 import '../../utils.dart'; | 34 import '../../utils.dart'; |
| 31 import '../context/abstract_context.dart'; | 35 import '../context/abstract_context.dart'; |
| 32 | 36 |
| 33 main() { | 37 main() { |
| 34 initializeTestEnvironment(); | 38 initializeTestEnvironment(); |
| 35 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 39 defineReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 36 runReflectiveTests(BuildDirectiveElementsTaskTest); | 40 defineReflectiveTests(BuildDirectiveElementsTaskTest); |
| 37 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 41 defineReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 38 runReflectiveTests(BuildExportNamespaceTaskTest); | 42 defineReflectiveTests(BuildExportNamespaceTaskTest); |
| 39 runReflectiveTests(BuildLibraryElementTaskTest); | 43 defineReflectiveTests(BuildLibraryElementTaskTest); |
| 40 runReflectiveTests(BuildPublicNamespaceTaskTest); | 44 defineReflectiveTests(BuildPublicNamespaceTaskTest); |
| 41 runReflectiveTests(BuildSourceExportClosureTaskTest); | 45 defineReflectiveTests(BuildSourceExportClosureTaskTest); |
| 42 runReflectiveTests(BuildSourceImportExportClosureTaskTest); | 46 defineReflectiveTests(BuildTypeProviderTaskTest); |
| 43 runReflectiveTests(BuildTypeProviderTaskTest); | 47 defineReflectiveTests(ComputeConstantDependenciesTaskTest); |
| 44 runReflectiveTests(ComputeConstantDependenciesTaskTest); | 48 defineReflectiveTests(ComputeConstantValueTaskTest); |
| 45 runReflectiveTests(ComputeConstantValueTaskTest); | 49 defineReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); |
| 46 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); | 50 defineReflectiveTests(ComputeLibraryCycleTaskTest); |
| 47 runReflectiveTests(ComputeLibraryCycleTaskTest); | 51 defineReflectiveTests(ContainingLibrariesTaskTest); |
| 48 runReflectiveTests(ContainingLibrariesTaskTest); | 52 defineReflectiveTests(DartErrorsTaskTest); |
| 49 runReflectiveTests(DartErrorsTaskTest); | 53 defineReflectiveTests(EvaluateUnitConstantsTaskTest); |
| 50 runReflectiveTests(EvaluateUnitConstantsTaskTest); | 54 defineReflectiveTests(GatherUsedImportedElementsTaskTest); |
| 51 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 55 defineReflectiveTests(GatherUsedLocalElementsTaskTest); |
| 52 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 56 defineReflectiveTests(GenerateHintsTaskTest); |
| 53 runReflectiveTests(GenerateHintsTaskTest); | 57 defineReflectiveTests(GenerateLintsTaskTest); |
| 54 runReflectiveTests(GenerateLintsTaskTest); | 58 defineReflectiveTests(InferInstanceMembersInUnitTaskTest); |
| 55 runReflectiveTests(InferInstanceMembersInUnitTaskTest); | 59 defineReflectiveTests(InferStaticVariableTypesInUnitTaskTest); |
| 56 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); | 60 defineReflectiveTests(InferStaticVariableTypeTaskTest); |
| 57 runReflectiveTests(InferStaticVariableTypeTaskTest); | 61 defineReflectiveTests(LibraryErrorsReadyTaskTest); |
| 58 runReflectiveTests(LibraryErrorsReadyTaskTest); | 62 defineReflectiveTests(LibraryUnitErrorsTaskTest); |
| 59 runReflectiveTests(LibraryUnitErrorsTaskTest); | 63 defineReflectiveTests(ParseDartTaskTest); |
| 60 runReflectiveTests(ParseDartTaskTest); | 64 defineReflectiveTests(PartiallyResolveUnitReferencesTaskTest); |
| 61 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); | 65 defineReflectiveTests(ReferencedNamesBuilderTest); |
| 62 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); | 66 defineReflectiveTests(ResolveDirectiveElementsTaskTest); |
| 63 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 67 defineReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); |
| 64 runReflectiveTests(ResolveUnitTaskTest); | 68 defineReflectiveTests(ResolveLibraryTaskTest); |
| 65 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 69 defineReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 66 runReflectiveTests(ResolveVariableReferencesTaskTest); | 70 defineReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest); |
| 67 runReflectiveTests(ScanDartTaskTest); | 71 defineReflectiveTests(ResolveUnitTaskTest); |
| 68 runReflectiveTests(StrongModeInferenceTest); | 72 defineReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 69 runReflectiveTests(StrongModeVerifyUnitTaskTest); | 73 defineReflectiveTests(ResolveVariableReferencesTaskTest); |
| 70 runReflectiveTests(VerifyUnitTaskTest); | 74 defineReflectiveTests(ScanDartTaskTest); |
| 75 defineReflectiveTests(StrongModeInferenceTest); |
| 76 defineReflectiveTests(StrongModeVerifyUnitTaskTest); |
| 77 defineReflectiveTests(VerifyUnitTaskTest); |
| 71 } | 78 } |
| 72 | 79 |
| 73 isInstanceOf isBuildCompilationUnitElementTask = | 80 isInstanceOf isBuildCompilationUnitElementTask = |
| 74 new isInstanceOf<BuildCompilationUnitElementTask>(); | 81 new isInstanceOf<BuildCompilationUnitElementTask>(); |
| 75 isInstanceOf isBuildDirectiveElementsTask = | 82 isInstanceOf isBuildDirectiveElementsTask = |
| 76 new isInstanceOf<BuildDirectiveElementsTask>(); | 83 new isInstanceOf<BuildDirectiveElementsTask>(); |
| 77 isInstanceOf isBuildEnumMemberElementsTask = | 84 isInstanceOf isBuildEnumMemberElementsTask = |
| 78 new isInstanceOf<BuildEnumMemberElementsTask>(); | 85 new isInstanceOf<BuildEnumMemberElementsTask>(); |
| 79 isInstanceOf isBuildExportNamespaceTask = | 86 isInstanceOf isBuildExportNamespaceTask = |
| 80 new isInstanceOf<BuildExportNamespaceTask>(); | 87 new isInstanceOf<BuildExportNamespaceTask>(); |
| 81 isInstanceOf isBuildLibraryElementTask = | 88 isInstanceOf isBuildLibraryElementTask = |
| 82 new isInstanceOf<BuildLibraryElementTask>(); | 89 new isInstanceOf<BuildLibraryElementTask>(); |
| 83 isInstanceOf isBuildPublicNamespaceTask = | 90 isInstanceOf isBuildPublicNamespaceTask = |
| 84 new isInstanceOf<BuildPublicNamespaceTask>(); | 91 new isInstanceOf<BuildPublicNamespaceTask>(); |
| 85 isInstanceOf isBuildSourceExportClosureTask = | 92 isInstanceOf isBuildSourceExportClosureTask = |
| 86 new isInstanceOf<BuildSourceExportClosureTask>(); | 93 new isInstanceOf<BuildSourceExportClosureTask>(); |
| 87 isInstanceOf isBuildSourceImportExportClosureTask = | |
| 88 new isInstanceOf<BuildSourceImportExportClosureTask>(); | |
| 89 isInstanceOf isBuildTypeProviderTask = | 94 isInstanceOf isBuildTypeProviderTask = |
| 90 new isInstanceOf<BuildTypeProviderTask>(); | 95 new isInstanceOf<BuildTypeProviderTask>(); |
| 91 isInstanceOf isComputeConstantDependenciesTask = | 96 isInstanceOf isComputeConstantDependenciesTask = |
| 92 new isInstanceOf<ComputeConstantDependenciesTask>(); | 97 new isInstanceOf<ComputeConstantDependenciesTask>(); |
| 93 isInstanceOf isComputeConstantValueTask = | 98 isInstanceOf isComputeConstantValueTask = |
| 94 new isInstanceOf<ComputeConstantValueTask>(); | 99 new isInstanceOf<ComputeConstantValueTask>(); |
| 95 isInstanceOf isComputeInferableStaticVariableDependenciesTask = | 100 isInstanceOf isComputeInferableStaticVariableDependenciesTask = |
| 96 new isInstanceOf<ComputeInferableStaticVariableDependenciesTask>(); | 101 new isInstanceOf<ComputeInferableStaticVariableDependenciesTask>(); |
| 97 isInstanceOf isContainingLibrariesTask = | 102 isInstanceOf isContainingLibrariesTask = |
| 98 new isInstanceOf<ContainingLibrariesTask>(); | 103 new isInstanceOf<ContainingLibrariesTask>(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); | 116 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); |
| 112 isInstanceOf isInferStaticVariableTypeTask = | 117 isInstanceOf isInferStaticVariableTypeTask = |
| 113 new isInstanceOf<InferStaticVariableTypeTask>(); | 118 new isInstanceOf<InferStaticVariableTypeTask>(); |
| 114 isInstanceOf isLibraryErrorsReadyTask = | 119 isInstanceOf isLibraryErrorsReadyTask = |
| 115 new isInstanceOf<LibraryErrorsReadyTask>(); | 120 new isInstanceOf<LibraryErrorsReadyTask>(); |
| 116 isInstanceOf isLibraryUnitErrorsTask = | 121 isInstanceOf isLibraryUnitErrorsTask = |
| 117 new isInstanceOf<LibraryUnitErrorsTask>(); | 122 new isInstanceOf<LibraryUnitErrorsTask>(); |
| 118 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); | 123 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); |
| 119 isInstanceOf isPartiallyResolveUnitReferencesTask = | 124 isInstanceOf isPartiallyResolveUnitReferencesTask = |
| 120 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); | 125 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
| 126 isInstanceOf isResolveDirectiveElementsTask = |
| 127 new isInstanceOf<ResolveDirectiveElementsTask>(); |
| 128 isInstanceOf isResolveLibraryReferencesTask = |
| 129 new isInstanceOf<ResolveLibraryReferencesTask>(); |
| 130 isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>(); |
| 121 isInstanceOf isResolveLibraryTypeNamesTask = | 131 isInstanceOf isResolveLibraryTypeNamesTask = |
| 122 new isInstanceOf<ResolveLibraryTypeNamesTask>(); | 132 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 133 isInstanceOf isResolveTopLevelUnitTypeBoundsTask = |
| 134 new isInstanceOf<ResolveTopLevelUnitTypeBoundsTask>(); |
| 123 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); | 135 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); |
| 124 isInstanceOf isResolveUnitTypeNamesTask = | 136 isInstanceOf isResolveUnitTypeNamesTask = |
| 125 new isInstanceOf<ResolveUnitTypeNamesTask>(); | 137 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
| 126 isInstanceOf isResolveVariableReferencesTask = | 138 isInstanceOf isResolveVariableReferencesTask = |
| 127 new isInstanceOf<ResolveVariableReferencesTask>(); | 139 new isInstanceOf<ResolveVariableReferencesTask>(); |
| 128 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); | 140 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); |
| 129 isInstanceOf isStrongModeVerifyUnitTask = | 141 isInstanceOf isStrongModeVerifyUnitTask = |
| 130 new isInstanceOf<StrongModeVerifyUnitTask>(); | 142 new isInstanceOf<StrongModeVerifyUnitTask>(); |
| 131 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); | 143 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
| 132 | 144 |
| 133 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); | 145 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); |
| 134 | 146 |
| 135 @reflectiveTest | 147 @reflectiveTest |
| 136 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 148 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 137 Source source; | 149 Source source; |
| 138 LibrarySpecificUnit target; | 150 LibrarySpecificUnit target; |
| 139 | 151 |
| 152 test_created_resolved_unit() { |
| 153 Source source = newSource( |
| 154 '/test.dart', |
| 155 r''' |
| 156 library lib; |
| 157 class A {} |
| 158 '''); |
| 159 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 160 computeResult(target, RESOLVED_UNIT1); |
| 161 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 162 expect(outputs[CREATED_RESOLVED_UNIT1], isTrue); |
| 163 } |
| 164 |
| 140 test_perform_find_constants() { | 165 test_perform_find_constants() { |
| 141 _performBuildTask(''' | 166 _performBuildTask(''' |
| 142 const x = 1; | 167 const x = 1; |
| 143 class C { | 168 class C { |
| 144 static const y = 1; | 169 static const y = 1; |
| 145 const C([p = 1]); | 170 const C([p = 1]); |
| 146 } | 171 } |
| 147 @x | 172 @x |
| 148 f() { | 173 f() { |
| 149 const z = 1; | 174 const z = 1; |
| 150 } | 175 } |
| 151 '''); | 176 '''); |
| 152 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 177 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 153 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; | 178 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; |
| 154 Annotation annotation = unit.declarations | 179 Annotation annotation = unit.declarations |
| 155 .firstWhere((m) => m is FunctionDeclaration) | 180 .firstWhere((m) => m is FunctionDeclaration) |
| 156 .metadata[0]; | 181 .metadata[0]; |
| 157 List<ConstantEvaluationTarget> expectedConstants = [ | 182 List<ConstantEvaluationTarget> expectedConstants = |
| 183 <ConstantEvaluationTarget>[ |
| 158 unitElement.accessors.firstWhere((e) => e.isGetter).variable, | 184 unitElement.accessors.firstWhere((e) => e.isGetter).variable, |
| 159 unitElement.types[0].fields[0], | 185 unitElement.types[0].fields[0], |
| 160 unitElement.functions[0].localVariables[0], | 186 unitElement.functions[0].localVariables[0], |
| 161 unitElement.types[0].constructors[0], | 187 unitElement.types[0].constructors[0], |
| 162 new ConstantEvaluationTarget_Annotation( | 188 annotation.elementAnnotation, |
| 163 context, source, source, annotation), | |
| 164 unitElement.types[0].constructors[0].parameters[0] | 189 unitElement.types[0].constructors[0].parameters[0] |
| 165 ]; | 190 ]; |
| 166 expect( | 191 expect( |
| 167 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet()); | 192 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet()); |
| 168 } | 193 } |
| 169 | 194 |
| 170 test_perform_library() { | 195 test_perform_library() { |
| 171 _performBuildTask(r''' | 196 _performBuildTask(r''' |
| 172 library lib; | 197 library lib; |
| 173 import 'lib2.dart'; | 198 import 'lib2.dart'; |
| 174 export 'lib3.dart'; | 199 export 'lib3.dart'; |
| 175 part 'part.dart'; | 200 part 'part.dart'; |
| 176 final x = ''; | 201 final x = ''; |
| 177 class A { | 202 class A { |
| 178 static final y = 0; | 203 static final y = 0; |
| 179 } | 204 } |
| 180 class B = Object with A; | 205 class B = Object with A; |
| 181 '''); | 206 '''); |
| 182 expect(outputs, hasLength(3)); | 207 expect(outputs, hasLength(4)); |
| 183 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull); | 208 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull); |
| 184 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 209 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 185 expect(outputs[RESOLVED_UNIT1], isNotNull); | 210 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 211 expect(outputs[CREATED_RESOLVED_UNIT1], isTrue); |
| 186 } | 212 } |
| 187 | 213 |
| 188 test_perform_reuseElement() { | 214 test_perform_reuseElement() { |
| 189 _performBuildTask(r''' | 215 _performBuildTask(r''' |
| 190 library lib; | 216 library lib; |
| 191 class A {} | 217 class A {} |
| 192 class B = Object with A; | 218 class B = Object with A; |
| 193 '''); | 219 '''); |
| 194 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 220 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 195 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; | 221 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 208 void _performBuildTask(String content) { | 234 void _performBuildTask(String content) { |
| 209 source = newSource('/test.dart', content); | 235 source = newSource('/test.dart', content); |
| 210 target = new LibrarySpecificUnit(source, source); | 236 target = new LibrarySpecificUnit(source, source); |
| 211 computeResult(target, RESOLVED_UNIT1, | 237 computeResult(target, RESOLVED_UNIT1, |
| 212 matcher: isBuildCompilationUnitElementTask); | 238 matcher: isBuildCompilationUnitElementTask); |
| 213 } | 239 } |
| 214 } | 240 } |
| 215 | 241 |
| 216 @reflectiveTest | 242 @reflectiveTest |
| 217 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 243 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 244 /** |
| 245 * Verify that the given [element] has exactly one annotation, and that its |
| 246 * [ElementAnnotationImpl] is unresolved and points back to [element]. |
| 247 * |
| 248 * The compilation unit stored in the [ElementAnnotationImpl] should be |
| 249 * [compilationUnit]. |
| 250 */ |
| 251 void checkMetadata(Element element, CompilationUnitElement compilationUnit) { |
| 252 expect(element.metadata, hasLength(1)); |
| 253 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); |
| 254 ElementAnnotationImpl elementAnnotation = element.metadata[0]; |
| 255 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 256 expect(elementAnnotation.compilationUnit, isNotNull); |
| 257 expect(elementAnnotation.compilationUnit, compilationUnit); |
| 258 } |
| 259 |
| 218 test_perform() { | 260 test_perform() { |
| 219 List<Source> sources = newSources({ | 261 List<Source> sources = newSources({ |
| 220 '/libA.dart': ''' | 262 '/libA.dart': ''' |
| 221 library libA; | 263 library libA; |
| 222 import 'libB.dart'; | 264 import 'libB.dart'; |
| 223 export 'libC.dart'; | 265 export 'libC.dart'; |
| 224 ''', | 266 ''', |
| 225 '/libB.dart': ''' | 267 '/libB.dart': ''' |
| 226 library libB; | 268 library libB; |
| 227 ''', | 269 ''', |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 expect(combinator.offset, 33); | 347 expect(combinator.offset, 33); |
| 306 expect(combinator.end, 42); | 348 expect(combinator.end, 42); |
| 307 expect(combinator.shownNames, ['A', 'B']); | 349 expect(combinator.shownNames, ['A', 'B']); |
| 308 } | 350 } |
| 309 { | 351 { |
| 310 HideElementCombinator combinator = combinators[1]; | 352 HideElementCombinator combinator = combinators[1]; |
| 311 expect(combinator.hiddenNames, ['C', 'D']); | 353 expect(combinator.hiddenNames, ['C', 'D']); |
| 312 } | 354 } |
| 313 } | 355 } |
| 314 | 356 |
| 357 test_perform_configurations_export() { |
| 358 context.declaredVariables.define('dart.library.io', 'true'); |
| 359 context.declaredVariables.define('dart.library.html', 'true'); |
| 360 newSource('/foo.dart', ''); |
| 361 var foo_io = newSource('/foo_io.dart', ''); |
| 362 newSource('/foo_html.dart', ''); |
| 363 var testSource = newSource( |
| 364 '/test.dart', |
| 365 r''' |
| 366 export 'foo.dart' |
| 367 if (dart.library.io) 'foo_io.dart' |
| 368 if (dart.library.html) 'foo_html.dart'; |
| 369 '''); |
| 370 // Perform the task. |
| 371 computeResult(testSource, LIBRARY_ELEMENT2, |
| 372 matcher: isBuildDirectiveElementsTask); |
| 373 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
| 374 // Validate the export element. |
| 375 ExportElement export = testLibrary.exports[0]; |
| 376 expect(export.exportedLibrary.source, foo_io); |
| 377 expect(export.uri, 'foo_io.dart'); |
| 378 } |
| 379 |
| 380 test_perform_configurations_import() { |
| 381 context.declaredVariables.define('dart.library.io', 'true'); |
| 382 context.declaredVariables.define('dart.library.html', 'true'); |
| 383 newSource('/foo.dart', ''); |
| 384 var foo_io = newSource('/foo_io.dart', ''); |
| 385 newSource('/foo_html.dart', ''); |
| 386 var testSource = newSource( |
| 387 '/test.dart', |
| 388 r''' |
| 389 import 'foo.dart' |
| 390 if (dart.library.io) 'foo_io.dart' |
| 391 if (dart.library.html) 'foo_html.dart'; |
| 392 '''); |
| 393 // Perform the task. |
| 394 computeResult(testSource, LIBRARY_ELEMENT2, |
| 395 matcher: isBuildDirectiveElementsTask); |
| 396 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
| 397 // Validate the import element. |
| 398 ImportElement import = testLibrary.imports[0]; |
| 399 expect(import.importedLibrary.source, foo_io); |
| 400 expect(import.uri, 'foo_io.dart'); |
| 401 } |
| 402 |
| 315 test_perform_dartCoreContext() { | 403 test_perform_dartCoreContext() { |
| 316 List<Source> sources = newSources({'/libA.dart': ''}); | 404 List<Source> sources = newSources({'/libA.dart': ''}); |
| 317 Source source = sources[0]; | 405 Source source = sources[0]; |
| 318 // perform task | 406 // perform task |
| 319 computeResult(source, LIBRARY_ELEMENT2, | 407 computeResult(source, LIBRARY_ELEMENT2, |
| 320 matcher: isBuildDirectiveElementsTask); | 408 matcher: isBuildDirectiveElementsTask); |
| 321 // prepare outputs | 409 // prepare outputs |
| 322 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 410 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 323 // verify that dart:core has SDK context | 411 // verify that dart:core has SDK context |
| 324 { | 412 { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 expect(importElementB.prefixOffset, prefixElement.nameOffset); | 523 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| 436 expect(prefixNodeB.staticElement, prefixElement); | 524 expect(prefixNodeB.staticElement, prefixElement); |
| 437 // PrefixElement "pref" is shared | 525 // PrefixElement "pref" is shared |
| 438 ImportDirective importNodeC = libraryUnitA.directives[2]; | 526 ImportDirective importNodeC = libraryUnitA.directives[2]; |
| 439 SimpleIdentifier prefixNodeC = importNodeC.prefix; | 527 SimpleIdentifier prefixNodeC = importNodeC.prefix; |
| 440 ImportElement importElementC = importNodeC.element; | 528 ImportElement importElementC = importNodeC.element; |
| 441 expect(prefixNodeC.staticElement, prefixElement); | 529 expect(prefixNodeC.staticElement, prefixElement); |
| 442 expect(importElementC.prefix, prefixElement); | 530 expect(importElementC.prefix, prefixElement); |
| 443 } | 531 } |
| 444 | 532 |
| 533 test_perform_metadata() { |
| 534 List<Source> sources = newSources({ |
| 535 '/libA.dart': ''' |
| 536 @a library libA; |
| 537 @b import 'libB.dart'; |
| 538 @c export 'libC.dart'; |
| 539 @d part 'part.dart';''', |
| 540 '/libB.dart': 'library libB;', |
| 541 '/libC.dart': 'library libC;', |
| 542 '/part.dart': 'part of libA;' |
| 543 }); |
| 544 Source sourceA = sources[0]; |
| 545 // perform task |
| 546 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 547 matcher: isBuildDirectiveElementsTask); |
| 548 // Get outputs |
| 549 LibraryElement libraryA = |
| 550 context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2); |
| 551 // Validate metadata |
| 552 checkMetadata(libraryA, libraryA.definingCompilationUnit); |
| 553 checkMetadata(libraryA.imports[0], libraryA.definingCompilationUnit); |
| 554 checkMetadata(libraryA.exports[0], libraryA.definingCompilationUnit); |
| 555 checkMetadata(libraryA.parts[0], libraryA.definingCompilationUnit); |
| 556 } |
| 557 |
| 558 test_perform_metadata_partOf() { |
| 559 // We don't record annotations on `part of` directives because the element |
| 560 // associated with a `part of` directive is the library, and the convention |
| 561 // is to annotate the library at the site of the `library` declaration. |
| 562 List<Source> sources = newSources({ |
| 563 '/libA.dart': ''' |
| 564 library libA; |
| 565 part 'part.dart';''', |
| 566 '/part.dart': '@a part of libA;' |
| 567 }); |
| 568 Source sourceA = sources[0]; |
| 569 Source sourcePart = sources[1]; |
| 570 // perform task |
| 571 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 572 matcher: isBuildDirectiveElementsTask); |
| 573 // Get outputs |
| 574 LibraryElement libraryA = |
| 575 context.getCacheEntry(sourceA).getValue(LIBRARY_ELEMENT2); |
| 576 CompilationUnit part = context |
| 577 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourcePart)) |
| 578 .getValue(RESOLVED_UNIT1); |
| 579 // Validate metadata |
| 580 expect(part.directives[0], new isInstanceOf<PartOfDirective>()); |
| 581 expect(part.directives[0].element, same(libraryA)); |
| 582 expect(part.directives[0].element.metadata, isEmpty); |
| 583 } |
| 584 |
| 445 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 585 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 446 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); | 586 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); |
| 447 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 587 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 448 } | 588 } |
| 449 | 589 |
| 450 _getExportLibraryInput(Source source) { | 590 _getExportLibraryInput(Source source) { |
| 451 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 591 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 452 return task.inputs[key][source]; | 592 return task.inputs[key][source]; |
| 453 } | 593 } |
| 454 | 594 |
| 455 _getImportLibraryInput(Source source) { | 595 _getImportLibraryInput(Source source) { |
| 456 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 596 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 457 return task.inputs[key][source]; | 597 return task.inputs[key][source]; |
| 458 } | 598 } |
| 459 } | 599 } |
| 460 | 600 |
| 461 @reflectiveTest | 601 @reflectiveTest |
| 462 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 602 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 603 test_created_resolved_unit() { |
| 604 Source source = newSource( |
| 605 '/test.dart', |
| 606 r''' |
| 607 library lib; |
| 608 class A {} |
| 609 '''); |
| 610 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 611 computeResult(target, RESOLVED_UNIT3); |
| 612 expect(outputs[RESOLVED_UNIT3], isNotNull); |
| 613 expect(outputs[CREATED_RESOLVED_UNIT3], isTrue); |
| 614 } |
| 615 |
| 463 test_perform() { | 616 test_perform() { |
| 464 Source source = newSource( | 617 Source source = newSource( |
| 465 '/test.dart', | 618 '/test.dart', |
| 466 ''' | 619 ''' |
| 467 enum MyEnum { | 620 enum MyEnum { |
| 468 A, B | 621 A, B |
| 469 } | 622 } |
| 470 '''); | 623 '''); |
| 471 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2, | 624 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT3, |
| 472 matcher: isBuildEnumMemberElementsTask); | 625 matcher: isBuildEnumMemberElementsTask); |
| 473 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 626 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 474 // validate Element | 627 // validate Element |
| 475 ClassElement enumElement = unit.element.getEnum('MyEnum'); | 628 ClassElement enumElement = unit.element.getEnum('MyEnum'); |
| 476 List<FieldElement> fields = enumElement.fields; | 629 List<FieldElement> fields = enumElement.fields; |
| 477 expect(fields, hasLength(4)); | 630 expect(fields, hasLength(4)); |
| 478 { | 631 { |
| 479 FieldElementImpl index = fields[0]; | 632 FieldElementImpl index = fields[0]; |
| 480 expect(index, isNotNull); | 633 expect(index, isNotNull); |
| 481 expect(index.name, 'index'); | 634 expect(index.name, 'index'); |
| 482 expect(index.isStatic, isFalse); | 635 expect(index.isStatic, isFalse); |
| 483 expect(index.evaluationResult, isNull); | 636 expect(index.evaluationResult, isNull); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 ''', | 987 ''', |
| 835 '/part1.dart': ''' | 988 '/part1.dart': ''' |
| 836 part of lib; | 989 part of lib; |
| 837 int get test => 0; | 990 int get test => 0; |
| 838 ''', | 991 ''', |
| 839 '/part2.dart': ''' | 992 '/part2.dart': ''' |
| 840 part of lib; | 993 part of lib; |
| 841 void set test(_) {} | 994 void set test(_) {} |
| 842 ''' | 995 ''' |
| 843 }); | 996 }); |
| 844 CompilationUnitElement unitElement1 = partUnits[0].element; | 997 CompilationUnitElement unitElement1 = partUnits |
| 845 CompilationUnitElement unitElement2 = partUnits[1].element; | 998 .singleWhere((u) => u.element.name.endsWith('part1.dart')) |
| 999 .element; |
| 1000 CompilationUnitElement unitElement2 = partUnits |
| 1001 .singleWhere((u) => u.element.name.endsWith('part2.dart')) |
| 1002 .element; |
| 846 PropertyAccessorElement getter = unitElement1.accessors[0]; | 1003 PropertyAccessorElement getter = unitElement1.accessors[0]; |
| 847 PropertyAccessorElement setter = unitElement2.accessors[0]; | 1004 PropertyAccessorElement setter = unitElement2.accessors[0]; |
| 848 PropertyInducingElement variable = getter.variable; | 1005 PropertyInducingElement variable = getter.variable; |
| 849 expect(getter.isGetter, isTrue); | 1006 expect(getter.isGetter, isTrue); |
| 850 expect(setter.isSetter, isTrue); | 1007 expect(setter.isSetter, isTrue); |
| 851 expect(variable, isNotNull); | 1008 expect(variable, isNotNull); |
| 852 expect(setter.variable, same(variable)); | 1009 expect(setter.variable, same(variable)); |
| 853 expect(unitElement1.topLevelVariables, [variable]); | 1010 expect(unitElement1.topLevelVariables, [variable]); |
| 854 expect(unitElement2.topLevelVariables, [variable]); | 1011 expect(unitElement2.topLevelVariables, [variable]); |
| 855 } | 1012 } |
| 856 | 1013 |
| 857 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 1014 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 858 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 1015 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 859 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 1016 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 860 } | 1017 } |
| 861 | 1018 |
| 862 void _performBuildTask(Map<String, String> sourceMap) { | 1019 void _performBuildTask(Map<String, String> sourceMap) { |
| 863 List<Source> sources = newSources(sourceMap); | 1020 List<Source> sources = newSources(sourceMap); |
| 864 Source libSource = sources.first; | 1021 Source libSource = sources.first; |
| 865 computeResult(libSource, LIBRARY_ELEMENT1, | 1022 computeResult(libSource, LIBRARY_ELEMENT1, |
| 866 matcher: isBuildLibraryElementTask); | 1023 matcher: isBuildLibraryElementTask); |
| 867 libraryUnit = context | 1024 libraryUnit = context |
| 868 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) | 1025 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) |
| 869 .getValue(RESOLVED_UNIT1); | 1026 .getValue(RESOLVED_UNIT1); |
| 870 libraryUnitElement = libraryUnit.element; | 1027 libraryUnitElement = libraryUnit.element; |
| 871 librarySource = libraryUnitElement.source; | 1028 librarySource = libraryUnitElement.source; |
| 872 libraryElement = outputs[LIBRARY_ELEMENT1]; | 1029 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 873 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; | 1030 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT] |
| 1031 as List<CompilationUnit>; |
| 874 } | 1032 } |
| 875 } | 1033 } |
| 876 | 1034 |
| 877 @reflectiveTest | 1035 @reflectiveTest |
| 878 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { | 1036 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { |
| 879 test_perform() { | 1037 test_perform() { |
| 880 List<Source> sources = newSources({ | 1038 List<Source> sources = newSources({ |
| 881 '/lib.dart': ''' | 1039 '/lib.dart': ''' |
| 882 library lib; | 1040 library lib; |
| 883 part 'part.dart'; | 1041 part 'part.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 894 matcher: isBuildPublicNamespaceTask); | 1052 matcher: isBuildPublicNamespaceTask); |
| 895 // validate | 1053 // validate |
| 896 LibraryElement library = outputs[LIBRARY_ELEMENT3]; | 1054 LibraryElement library = outputs[LIBRARY_ELEMENT3]; |
| 897 Namespace namespace = library.publicNamespace; | 1055 Namespace namespace = library.publicNamespace; |
| 898 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); | 1056 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); |
| 899 } | 1057 } |
| 900 } | 1058 } |
| 901 | 1059 |
| 902 @reflectiveTest | 1060 @reflectiveTest |
| 903 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { | 1061 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { |
| 1062 List<Source> getExportSourceClosure(Map<ResultDescriptor, dynamic> outputs) { |
| 1063 return outputs[EXPORT_SOURCE_CLOSURE] as List<Source>; |
| 1064 } |
| 1065 |
| 904 test_perform_exportClosure() { | 1066 test_perform_exportClosure() { |
| 905 Source sourceA = newSource( | 1067 Source sourceA = newSource( |
| 906 '/a.dart', | 1068 '/a.dart', |
| 907 ''' | 1069 ''' |
| 908 library lib_a; | 1070 library lib_a; |
| 909 export 'b.dart'; | 1071 export 'b.dart'; |
| 910 '''); | 1072 '''); |
| 911 Source sourceB = newSource( | 1073 Source sourceB = newSource( |
| 912 '/b.dart', | 1074 '/b.dart', |
| 913 ''' | 1075 ''' |
| 914 library lib_b; | 1076 library lib_b; |
| 915 export 'c.dart'; | 1077 export 'c.dart'; |
| 916 '''); | 1078 '''); |
| 917 Source sourceC = newSource( | 1079 Source sourceC = newSource( |
| 918 '/c.dart', | 1080 '/c.dart', |
| 919 ''' | 1081 ''' |
| 920 library lib_c; | 1082 library lib_c; |
| 921 export 'a.dart'; | 1083 export 'a.dart'; |
| 922 '''); | 1084 '''); |
| 923 Source sourceD = newSource( | 1085 Source sourceD = newSource( |
| 924 '/d.dart', | 1086 '/d.dart', |
| 925 ''' | 1087 ''' |
| 926 library lib_d; | 1088 library lib_d; |
| 927 '''); | 1089 '''); |
| 928 // a.dart | 1090 // a.dart |
| 929 { | 1091 { |
| 930 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, | 1092 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, |
| 931 matcher: isBuildSourceExportClosureTask); | 1093 matcher: isBuildSourceExportClosureTask); |
| 932 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1094 List<Source> closure = getExportSourceClosure(outputs); |
| 933 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1095 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 934 } | 1096 } |
| 935 // c.dart | 1097 // c.dart |
| 936 { | 1098 { |
| 937 computeResult(sourceC, EXPORT_SOURCE_CLOSURE, | 1099 computeResult(sourceC, EXPORT_SOURCE_CLOSURE, |
| 938 matcher: isBuildSourceExportClosureTask); | 1100 matcher: isBuildSourceExportClosureTask); |
| 939 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1101 List<Source> closure = getExportSourceClosure(outputs); |
| 940 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1102 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 941 } | 1103 } |
| 942 // d.dart | 1104 // d.dart |
| 943 { | 1105 { |
| 944 computeResult(sourceD, EXPORT_SOURCE_CLOSURE, | 1106 computeResult(sourceD, EXPORT_SOURCE_CLOSURE, |
| 945 matcher: isBuildSourceExportClosureTask); | 1107 matcher: isBuildSourceExportClosureTask); |
| 946 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1108 List<Source> closure = getExportSourceClosure(outputs); |
| 947 expect(closure, unorderedEquals([sourceD])); | 1109 expect(closure, unorderedEquals([sourceD])); |
| 948 } | 1110 } |
| 949 } | 1111 } |
| 950 } | 1112 } |
| 951 | 1113 |
| 952 @reflectiveTest | 1114 @reflectiveTest |
| 953 class BuildSourceImportExportClosureTaskTest extends _AbstractDartTaskTest { | |
| 954 test_perform_importExportClosure() { | |
| 955 Source sourceA = newSource( | |
| 956 '/a.dart', | |
| 957 ''' | |
| 958 library lib_a; | |
| 959 '''); | |
| 960 Source sourceB = newSource( | |
| 961 '/b.dart', | |
| 962 ''' | |
| 963 library lib_b; | |
| 964 export 'a.dart'; | |
| 965 '''); | |
| 966 Source sourceC = newSource( | |
| 967 '/c.dart', | |
| 968 ''' | |
| 969 library lib_c; | |
| 970 import 'b.dart'; | |
| 971 '''); | |
| 972 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); | |
| 973 // c.dart | |
| 974 { | |
| 975 computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE, | |
| 976 matcher: isBuildSourceImportExportClosureTask); | |
| 977 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; | |
| 978 expect(closure, contains(sourceA)); | |
| 979 expect(closure, contains(sourceB)); | |
| 980 expect(closure, contains(sourceC)); | |
| 981 expect(closure, contains(coreSource)); | |
| 982 } | |
| 983 // b.dart | |
| 984 { | |
| 985 computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE, | |
| 986 matcher: isBuildSourceImportExportClosureTask); | |
| 987 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; | |
| 988 expect(closure, contains(sourceA)); | |
| 989 expect(closure, contains(sourceB)); | |
| 990 expect(closure, contains(coreSource)); | |
| 991 } | |
| 992 } | |
| 993 | |
| 994 test_perform_isClient_false() { | |
| 995 Source sourceA = newSource( | |
| 996 '/a.dart', | |
| 997 ''' | |
| 998 library lib_a; | |
| 999 import 'b.dart'; | |
| 1000 '''); | |
| 1001 newSource( | |
| 1002 '/b.dart', | |
| 1003 ''' | |
| 1004 library lib_b; | |
| 1005 '''); | |
| 1006 computeResult(sourceA, IS_CLIENT, | |
| 1007 matcher: isBuildSourceImportExportClosureTask); | |
| 1008 expect(outputs[IS_CLIENT], isFalse); | |
| 1009 } | |
| 1010 | |
| 1011 test_perform_isClient_true_export_indirect() { | |
| 1012 newSource( | |
| 1013 '/exports_html.dart', | |
| 1014 ''' | |
| 1015 library lib_exports_html; | |
| 1016 export 'dart:html'; | |
| 1017 '''); | |
| 1018 Source source = newSource( | |
| 1019 '/test.dart', | |
| 1020 ''' | |
| 1021 import 'exports_html.dart'; | |
| 1022 '''); | |
| 1023 computeResult(source, IS_CLIENT, | |
| 1024 matcher: isBuildSourceImportExportClosureTask); | |
| 1025 expect(outputs[IS_CLIENT], isTrue); | |
| 1026 } | |
| 1027 | |
| 1028 test_perform_isClient_true_import_direct() { | |
| 1029 Source sourceA = newSource( | |
| 1030 '/a.dart', | |
| 1031 ''' | |
| 1032 library lib_a; | |
| 1033 import 'dart:html'; | |
| 1034 '''); | |
| 1035 computeResult(sourceA, IS_CLIENT, | |
| 1036 matcher: isBuildSourceImportExportClosureTask); | |
| 1037 expect(outputs[IS_CLIENT], isTrue); | |
| 1038 } | |
| 1039 | |
| 1040 test_perform_isClient_true_import_indirect() { | |
| 1041 Source sourceA = newSource( | |
| 1042 '/a.dart', | |
| 1043 ''' | |
| 1044 library lib_a; | |
| 1045 import 'b.dart'; | |
| 1046 '''); | |
| 1047 newSource( | |
| 1048 '/b.dart', | |
| 1049 ''' | |
| 1050 library lib_b; | |
| 1051 import 'dart:html'; | |
| 1052 '''); | |
| 1053 computeResult(sourceA, IS_CLIENT, | |
| 1054 matcher: isBuildSourceImportExportClosureTask); | |
| 1055 expect(outputs[IS_CLIENT], isTrue); | |
| 1056 } | |
| 1057 } | |
| 1058 | |
| 1059 @reflectiveTest | |
| 1060 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { | 1115 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { |
| 1061 test_perform() { | 1116 test_perform() { |
| 1062 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER, | 1117 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER, |
| 1063 matcher: isBuildTypeProviderTask); | 1118 matcher: isBuildTypeProviderTask); |
| 1064 // validate | 1119 // validate |
| 1065 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; | 1120 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; |
| 1066 expect(typeProvider, isNotNull); | 1121 expect(typeProvider, isNotNull); |
| 1067 expect(typeProvider.boolType, isNotNull); | 1122 expect(typeProvider.boolType, isNotNull); |
| 1068 expect(typeProvider.intType, isNotNull); | 1123 expect(typeProvider.intType, isNotNull); |
| 1069 expect(typeProvider.futureType, isNotNull); | 1124 expect(typeProvider.futureType, isNotNull); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 .firstWhere((PropertyAccessorElement accessor) => | 1157 .firstWhere((PropertyAccessorElement accessor) => |
| 1103 accessor.isGetter && accessor.name == 'x') | 1158 accessor.isGetter && accessor.name == 'x') |
| 1104 .variable; | 1159 .variable; |
| 1105 List<ClassElement> types = unit.element.types; | 1160 List<ClassElement> types = unit.element.types; |
| 1106 Element constructorForD = | 1161 Element constructorForD = |
| 1107 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; | 1162 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; |
| 1108 Annotation annotation = findClassAnnotation(unit, 'C'); | 1163 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1109 // Now compute the dependencies for the annotation, and check that it is | 1164 // Now compute the dependencies for the annotation, and check that it is |
| 1110 // the set [x, constructorForD]. | 1165 // the set [x, constructorForD]. |
| 1111 // TODO(paulberry): test librarySource != source | 1166 // TODO(paulberry): test librarySource != source |
| 1112 computeResult( | 1167 computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
| 1113 new ConstantEvaluationTarget_Annotation( | |
| 1114 context, source, source, annotation), | |
| 1115 CONSTANT_DEPENDENCIES, | |
| 1116 matcher: isComputeConstantDependenciesTask); | 1168 matcher: isComputeConstantDependenciesTask); |
| 1117 expect( | 1169 expect( |
| 1118 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); | 1170 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); |
| 1119 } | 1171 } |
| 1120 | 1172 |
| 1173 test_annotation_with_nonConstArg() { |
| 1174 Source source = newSource( |
| 1175 '/test.dart', |
| 1176 ''' |
| 1177 class A { |
| 1178 const A(x); |
| 1179 } |
| 1180 class C { |
| 1181 @A(const [(_) => null]) |
| 1182 String s; |
| 1183 } |
| 1184 '''); |
| 1185 // First compute the resolved unit for the source. |
| 1186 LibrarySpecificUnit librarySpecificUnit = |
| 1187 new LibrarySpecificUnit(source, source); |
| 1188 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1189 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1190 // Find the annotation on the field. |
| 1191 ClassDeclaration classC = unit.declarations[1]; |
| 1192 Annotation annotation = classC.members[0].metadata[0]; |
| 1193 // Now compute the dependencies for the annotation, and check that it is |
| 1194 // the right size. |
| 1195 computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
| 1196 matcher: isComputeConstantDependenciesTask); |
| 1197 expect(outputs[CONSTANT_DEPENDENCIES], hasLength(1)); |
| 1198 } |
| 1199 |
| 1121 test_annotation_without_args() { | 1200 test_annotation_without_args() { |
| 1122 Source source = newSource( | 1201 Source source = newSource( |
| 1123 '/test.dart', | 1202 '/test.dart', |
| 1124 ''' | 1203 ''' |
| 1125 const x = 1; | 1204 const x = 1; |
| 1126 @x class C {} | 1205 @x class C {} |
| 1127 '''); | 1206 '''); |
| 1128 // First compute the resolved unit for the source. | 1207 // First compute the resolved unit for the source. |
| 1129 LibrarySpecificUnit librarySpecificUnit = | 1208 LibrarySpecificUnit librarySpecificUnit = |
| 1130 new LibrarySpecificUnit(source, source); | 1209 new LibrarySpecificUnit(source, source); |
| 1131 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1210 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1132 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1211 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1133 // Find the element for x and the annotation on C. | 1212 // Find the element for x and the annotation on C. |
| 1134 List<PropertyAccessorElement> accessors = unit.element.accessors; | 1213 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1135 Element x = accessors | 1214 Element x = accessors |
| 1136 .firstWhere((PropertyAccessorElement accessor) => | 1215 .firstWhere((PropertyAccessorElement accessor) => |
| 1137 accessor.isGetter && accessor.name == 'x') | 1216 accessor.isGetter && accessor.name == 'x') |
| 1138 .variable; | 1217 .variable; |
| 1139 Annotation annotation = findClassAnnotation(unit, 'C'); | 1218 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1140 // Now compute the dependencies for the annotation, and check that it is | 1219 // Now compute the dependencies for the annotation, and check that it is |
| 1141 // the list [x]. | 1220 // the list [x]. |
| 1142 computeResult( | 1221 computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
| 1143 new ConstantEvaluationTarget_Annotation( | |
| 1144 context, source, source, annotation), | |
| 1145 CONSTANT_DEPENDENCIES, | |
| 1146 matcher: isComputeConstantDependenciesTask); | 1222 matcher: isComputeConstantDependenciesTask); |
| 1147 expect(outputs[CONSTANT_DEPENDENCIES], [x]); | 1223 expect(outputs[CONSTANT_DEPENDENCIES], [x]); |
| 1148 } | 1224 } |
| 1149 | 1225 |
| 1150 test_enumConstant() { | 1226 test_enumConstant() { |
| 1151 Source source = newSource( | 1227 Source source = newSource( |
| 1152 '/test.dart', | 1228 '/test.dart', |
| 1153 ''' | 1229 ''' |
| 1154 enum E {A, B, C} | 1230 enum E {A, B, C} |
| 1155 '''); | 1231 '''); |
| 1156 // First compute the resolved unit for the source. | 1232 // First compute the resolved unit for the source. |
| 1157 LibrarySpecificUnit librarySpecificUnit = | 1233 LibrarySpecificUnit librarySpecificUnit = |
| 1158 new LibrarySpecificUnit(source, source); | 1234 new LibrarySpecificUnit(source, source); |
| 1159 computeResult(librarySpecificUnit, RESOLVED_UNIT2); | 1235 computeResult(librarySpecificUnit, RESOLVED_UNIT3); |
| 1160 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 1236 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 1161 // Find the element for 'A' | 1237 // Find the element for 'A' |
| 1162 EnumDeclaration enumDeclaration = unit.declarations[0]; | 1238 EnumDeclaration enumDeclaration = unit.declarations[0]; |
| 1163 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; | 1239 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; |
| 1164 FieldElement constantElement = constantDeclaration.element; | 1240 FieldElement constantElement = constantDeclaration.element; |
| 1165 // Now compute the dependencies for the constant and check that there are | 1241 // Now compute the dependencies for the constant and check that there are |
| 1166 // none. | 1242 // none. |
| 1167 computeResult(constantElement, CONSTANT_DEPENDENCIES, | 1243 computeResult(constantElement, CONSTANT_DEPENDENCIES, |
| 1168 matcher: isComputeConstantDependenciesTask); | 1244 matcher: isComputeConstantDependenciesTask); |
| 1169 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); | 1245 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); |
| 1170 } | 1246 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1199 } | 1275 } |
| 1200 | 1276 |
| 1201 @reflectiveTest | 1277 @reflectiveTest |
| 1202 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { | 1278 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { |
| 1203 EvaluationResultImpl computeClassAnnotation( | 1279 EvaluationResultImpl computeClassAnnotation( |
| 1204 Source source, CompilationUnit unit, String className) { | 1280 Source source, CompilationUnit unit, String className) { |
| 1205 for (CompilationUnitMember member in unit.declarations) { | 1281 for (CompilationUnitMember member in unit.declarations) { |
| 1206 if (member is ClassDeclaration && member.name.name == className) { | 1282 if (member is ClassDeclaration && member.name.name == className) { |
| 1207 expect(member.metadata, hasLength(1)); | 1283 expect(member.metadata, hasLength(1)); |
| 1208 Annotation annotation = member.metadata[0]; | 1284 Annotation annotation = member.metadata[0]; |
| 1209 ConstantEvaluationTarget_Annotation target = | 1285 ElementAnnotationImpl target = annotation.elementAnnotation; |
| 1210 new ConstantEvaluationTarget_Annotation( | |
| 1211 context, source, source, annotation); | |
| 1212 computeResult(target, CONSTANT_VALUE, | 1286 computeResult(target, CONSTANT_VALUE, |
| 1213 matcher: isComputeConstantValueTask); | 1287 matcher: isComputeConstantValueTask); |
| 1214 expect(outputs[CONSTANT_VALUE], same(target)); | 1288 expect(outputs[CONSTANT_VALUE], same(target)); |
| 1215 EvaluationResultImpl evaluationResult = (annotation.elementAnnotation | 1289 EvaluationResultImpl evaluationResult = |
| 1216 as ElementAnnotationImpl).evaluationResult; | 1290 (annotation.elementAnnotation as ElementAnnotationImpl) |
| 1291 .evaluationResult; |
| 1217 return evaluationResult; | 1292 return evaluationResult; |
| 1218 } | 1293 } |
| 1219 } | 1294 } |
| 1220 fail('Annotation not found'); | 1295 fail('Annotation not found'); |
| 1221 return null; | 1296 return null; |
| 1222 } | 1297 } |
| 1223 | 1298 |
| 1224 test_annotation_non_const_constructor() { | 1299 test_annotation_non_const_constructor() { |
| 1225 // Calling a non-const constructor from an annotation that is illegal, but | 1300 // Calling a non-const constructor from an annotation that is illegal, but |
| 1226 // shouldn't crash analysis. | 1301 // shouldn't crash analysis. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 | 1448 |
| 1374 void _checkCircularities( | 1449 void _checkCircularities( |
| 1375 String variableName, List<String> otherVariables, String content) { | 1450 String variableName, List<String> otherVariables, String content) { |
| 1376 // Evaluating the first constant should produce an error. | 1451 // Evaluating the first constant should produce an error. |
| 1377 CompilationUnit unit = _resolveUnit(content); | 1452 CompilationUnit unit = _resolveUnit(content); |
| 1378 _expectCircularityError(_evaluateConstant(unit, variableName)); | 1453 _expectCircularityError(_evaluateConstant(unit, variableName)); |
| 1379 // And all the other constants involved in the strongly connected component | 1454 // And all the other constants involved in the strongly connected component |
| 1380 // should be set to the same error state. | 1455 // should be set to the same error state. |
| 1381 for (String otherVariableName in otherVariables) { | 1456 for (String otherVariableName in otherVariables) { |
| 1382 PropertyInducingElement otherVariableElement = | 1457 PropertyInducingElement otherVariableElement = |
| 1383 _findVariable(unit, otherVariableName); | 1458 AstFinder.getTopLevelVariableElement(unit, otherVariableName); |
| 1384 _expectCircularityError((otherVariableElement | 1459 _expectCircularityError( |
| 1385 as TopLevelVariableElementImpl).evaluationResult); | 1460 (otherVariableElement as TopLevelVariableElementImpl) |
| 1461 .evaluationResult); |
| 1386 } | 1462 } |
| 1387 } | 1463 } |
| 1388 | 1464 |
| 1389 EvaluationResultImpl _computeTopLevelVariableConstValue( | 1465 EvaluationResultImpl _computeTopLevelVariableConstValue( |
| 1390 String variableName, String content) { | 1466 String variableName, String content) { |
| 1391 return _evaluateConstant(_resolveUnit(content), variableName); | 1467 return _evaluateConstant(_resolveUnit(content), variableName); |
| 1392 } | 1468 } |
| 1393 | 1469 |
| 1394 EvaluationResultImpl _evaluateConstant( | 1470 EvaluationResultImpl _evaluateConstant( |
| 1395 CompilationUnit unit, String variableName) { | 1471 CompilationUnit unit, String variableName) { |
| 1396 // Find the element for the given constant. | 1472 // Find the element for the given constant. |
| 1397 PropertyInducingElement variableElement = _findVariable(unit, variableName); | 1473 PropertyInducingElement variableElement = |
| 1474 AstFinder.getTopLevelVariableElement(unit, variableName); |
| 1398 // Now compute the value of the constant. | 1475 // Now compute the value of the constant. |
| 1399 computeResult(variableElement, CONSTANT_VALUE, | 1476 computeResult(variableElement, CONSTANT_VALUE, |
| 1400 matcher: isComputeConstantValueTask); | 1477 matcher: isComputeConstantValueTask); |
| 1401 expect(outputs[CONSTANT_VALUE], same(variableElement)); | 1478 expect(outputs[CONSTANT_VALUE], same(variableElement)); |
| 1402 EvaluationResultImpl evaluationResult = | 1479 EvaluationResultImpl evaluationResult = |
| 1403 (variableElement as TopLevelVariableElementImpl).evaluationResult; | 1480 (variableElement as TopLevelVariableElementImpl).evaluationResult; |
| 1404 return evaluationResult; | 1481 return evaluationResult; |
| 1405 } | 1482 } |
| 1406 | 1483 |
| 1407 void _expectCircularityError(EvaluationResultImpl evaluationResult) { | 1484 void _expectCircularityError(EvaluationResultImpl evaluationResult) { |
| 1408 expect(evaluationResult, isNotNull); | 1485 expect(evaluationResult, isNotNull); |
| 1409 expect(evaluationResult.value, isNull); | 1486 expect(evaluationResult.value, isNull); |
| 1410 expect(evaluationResult.errors, hasLength(1)); | 1487 expect(evaluationResult.errors, hasLength(1)); |
| 1411 expect(evaluationResult.errors[0].errorCode, | 1488 expect(evaluationResult.errors[0].errorCode, |
| 1412 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT); | 1489 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT); |
| 1413 } | 1490 } |
| 1414 | 1491 |
| 1415 PropertyInducingElement _findVariable( | |
| 1416 CompilationUnit unit, String variableName) { | |
| 1417 // Find the element for the given constant. | |
| 1418 return unit.element.topLevelVariables.firstWhere( | |
| 1419 (TopLevelVariableElement variable) => variable.name == variableName); | |
| 1420 } | |
| 1421 | |
| 1422 CompilationUnit _resolveSource(Source source) { | 1492 CompilationUnit _resolveSource(Source source) { |
| 1423 LibrarySpecificUnit librarySpecificUnit = | 1493 LibrarySpecificUnit librarySpecificUnit = |
| 1424 new LibrarySpecificUnit(source, source); | 1494 new LibrarySpecificUnit(source, source); |
| 1425 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1495 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1426 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1496 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1427 return unit; | 1497 return unit; |
| 1428 } | 1498 } |
| 1429 | 1499 |
| 1430 CompilationUnit _resolveUnit(String content) => | 1500 CompilationUnit _resolveUnit(String content) => |
| 1431 _resolveSource(newSource('/test.dart', content)); | 1501 _resolveSource(newSource('/test.dart', content)); |
| 1432 } | 1502 } |
| 1433 | 1503 |
| 1434 @reflectiveTest | 1504 @reflectiveTest |
| 1435 class ComputeInferableStaticVariableDependenciesTaskTest | 1505 class ComputeInferableStaticVariableDependenciesTaskTest |
| 1436 extends _AbstractDartTaskTest { | 1506 extends _AbstractDartTaskTest { |
| 1437 @override | 1507 @override |
| 1438 void setUp() { | 1508 void setUp() { |
| 1439 super.setUp(); | 1509 super.setUp(); |
| 1440 // Variable dependencies are only available in strong mode. | 1510 // Variable dependencies are only available in strong mode. |
| 1441 enableStrongMode(); | 1511 enableStrongMode(); |
| 1442 } | 1512 } |
| 1443 | 1513 |
| 1514 test_created_resolved_unit() { |
| 1515 Source source = newSource( |
| 1516 '/test.dart', |
| 1517 r''' |
| 1518 library lib; |
| 1519 class A {} |
| 1520 '''); |
| 1521 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1522 computeResult(target, RESOLVED_UNIT7); |
| 1523 expect(outputs[RESOLVED_UNIT7], isNotNull); |
| 1524 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue); |
| 1525 } |
| 1526 |
| 1444 test_perform() { | 1527 test_perform() { |
| 1445 AnalysisTarget source = newSource( | 1528 AnalysisTarget source = newSource( |
| 1446 '/test.dart', | 1529 '/test.dart', |
| 1447 ''' | 1530 ''' |
| 1448 const a = b; | 1531 const a = b; |
| 1449 const b = 0; | 1532 const b = 0; |
| 1450 '''); | 1533 '''); |
| 1451 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1534 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1452 computeResult(target, RESOLVED_UNIT5); | 1535 computeResult(target, RESOLVED_UNIT7); |
| 1453 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1536 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 1454 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; | 1537 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; |
| 1455 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; | 1538 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; |
| 1456 | 1539 |
| 1457 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, | 1540 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, |
| 1458 matcher: isComputeInferableStaticVariableDependenciesTask); | 1541 matcher: isComputeInferableStaticVariableDependenciesTask); |
| 1459 expect(outputs, hasLength(1)); | 1542 expect(outputs, hasLength(1)); |
| 1460 List<VariableElement> dependencies = | 1543 List<VariableElement> dependencies = outputs[ |
| 1461 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]; | 1544 INFERABLE_STATIC_VARIABLE_DEPENDENCIES] as List<VariableElement>; |
| 1462 expect(dependencies, unorderedEquals([elementB])); | 1545 expect(dependencies, unorderedEquals([elementB])); |
| 1463 } | 1546 } |
| 1464 } | 1547 } |
| 1465 | 1548 |
| 1466 @reflectiveTest | 1549 @reflectiveTest |
| 1467 class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest { | 1550 class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest { |
| 1551 List<LibraryElement> getLibraryCycle(Map<ResultDescriptor, dynamic> outputs) { |
| 1552 return outputs[LIBRARY_CYCLE] as List<LibraryElement>; |
| 1553 } |
| 1554 |
| 1555 List<LibrarySpecificUnit> getLibraryCycleDependencies( |
| 1556 Map<ResultDescriptor, dynamic> outputs) { |
| 1557 return outputs[LIBRARY_CYCLE_DEPENDENCIES] as List<LibrarySpecificUnit>; |
| 1558 } |
| 1559 |
| 1560 List<LibrarySpecificUnit> getLibraryCycleUnits( |
| 1561 Map<ResultDescriptor, dynamic> outputs) { |
| 1562 return outputs[LIBRARY_CYCLE_UNITS] as List<LibrarySpecificUnit>; |
| 1563 } |
| 1564 |
| 1468 @override | 1565 @override |
| 1469 void setUp() { | 1566 void setUp() { |
| 1470 super.setUp(); | 1567 super.setUp(); |
| 1471 enableStrongMode(); | 1568 enableStrongMode(); |
| 1472 } | 1569 } |
| 1473 | 1570 |
| 1571 void test_library_cycle_incremental() { |
| 1572 enableStrongMode(); |
| 1573 Source a = newSource( |
| 1574 '/a.dart', |
| 1575 ''' |
| 1576 library a; |
| 1577 '''); |
| 1578 Source b = newSource( |
| 1579 '/b.dart', |
| 1580 ''' |
| 1581 library b; |
| 1582 import 'a.dart'; |
| 1583 '''); |
| 1584 Source c = newSource( |
| 1585 '/c.dart', |
| 1586 ''' |
| 1587 library c; |
| 1588 import 'b.dart'; |
| 1589 '''); |
| 1590 |
| 1591 _assertLibraryCycle(a, [a]); |
| 1592 _assertLibraryCycle(b, [b]); |
| 1593 _assertLibraryCycle(c, [c]); |
| 1594 |
| 1595 // Create a cycle. |
| 1596 context.setContents( |
| 1597 a, |
| 1598 ''' |
| 1599 library a; |
| 1600 import 'c.dart'; |
| 1601 '''); |
| 1602 _expectInvalid(a); |
| 1603 _expectInvalid(b); |
| 1604 _expectInvalid(c); |
| 1605 |
| 1606 _assertLibraryCycle(a, [a, b, c]); |
| 1607 _assertLibraryCycle(b, [a, b, c]); |
| 1608 _assertLibraryCycle(c, [a, b, c]); |
| 1609 |
| 1610 // Break the cycle again. |
| 1611 context.setContents( |
| 1612 a, |
| 1613 ''' |
| 1614 library a; |
| 1615 '''); |
| 1616 _expectInvalid(a); |
| 1617 _expectInvalid(b); |
| 1618 _expectInvalid(c); |
| 1619 |
| 1620 _assertLibraryCycle(a, [a]); |
| 1621 _assertLibraryCycle(b, [b]); |
| 1622 _assertLibraryCycle(c, [c]); |
| 1623 } |
| 1624 |
| 1625 void test_library_cycle_incremental_partial() { |
| 1626 enableStrongMode(); |
| 1627 Source a = newSource( |
| 1628 '/a.dart', |
| 1629 r''' |
| 1630 library a; |
| 1631 '''); |
| 1632 Source b = newSource( |
| 1633 '/b.dart', |
| 1634 r''' |
| 1635 library b; |
| 1636 import 'a.dart'; |
| 1637 '''); |
| 1638 Source c = newSource( |
| 1639 '/c.dart', |
| 1640 r''' |
| 1641 library c; |
| 1642 import 'b.dart'; |
| 1643 '''); |
| 1644 |
| 1645 _assertLibraryCycle(a, [a]); |
| 1646 _assertLibraryCycle(b, [b]); |
| 1647 // 'c' is not reachable, so we have not yet computed its library cycles. |
| 1648 |
| 1649 // Complete the cycle, via 'c'. |
| 1650 context.setContents( |
| 1651 a, |
| 1652 r''' |
| 1653 library a; |
| 1654 import 'c.dart'; |
| 1655 '''); |
| 1656 _expectInvalid(a); |
| 1657 _expectInvalid(b); |
| 1658 _expectInvalid(c); |
| 1659 |
| 1660 // Ensure that everything reachable through 'c' was invalidated, |
| 1661 // and recomputed to include all three sources. |
| 1662 _assertLibraryCycle(a, [a, b, c]); |
| 1663 _assertLibraryCycle(b, [a, b, c]); |
| 1664 _assertLibraryCycle(c, [a, b, c]); |
| 1665 } |
| 1666 |
| 1667 void test_library_cycle_incremental_partial2() { |
| 1668 enableStrongMode(); |
| 1669 Source a = newSource( |
| 1670 '/a.dart', |
| 1671 r''' |
| 1672 library a; |
| 1673 import 'b.dart'; |
| 1674 '''); |
| 1675 Source b = newSource( |
| 1676 '/b.dart', |
| 1677 r''' |
| 1678 library b; |
| 1679 import 'a.dart'; |
| 1680 '''); |
| 1681 Source c = newSource( |
| 1682 '/c.dart', |
| 1683 r''' |
| 1684 library c; |
| 1685 import 'b.dart'; |
| 1686 '''); |
| 1687 |
| 1688 _assertLibraryCycle(a, [a, b]); |
| 1689 _assertLibraryCycle(b, [a, b]); |
| 1690 _assertLibraryCycle(c, [c]); |
| 1691 |
| 1692 // Include 'c' into the cycle. |
| 1693 context.setContents( |
| 1694 a, |
| 1695 r''' |
| 1696 library a; |
| 1697 import 'b.dart'; |
| 1698 import 'c.dart'; |
| 1699 '''); |
| 1700 _expectInvalid(a); |
| 1701 _expectInvalid(b); |
| 1702 _expectInvalid(c); |
| 1703 |
| 1704 // Start processing with 'b', so that when we resolve 'b' directives, |
| 1705 // and invalidate library cycles, the 'a' directives are not resolved yet, |
| 1706 // so we don't know that the cycle must include 'c'. |
| 1707 _assertLibraryCycle(b, [a, b, c]); |
| 1708 _assertLibraryCycle(a, [a, b, c]); |
| 1709 _assertLibraryCycle(c, [a, b, c]); |
| 1710 } |
| 1711 |
| 1474 void test_library_cycle_linear() { | 1712 void test_library_cycle_linear() { |
| 1475 List<Source> sources = newSources({ | 1713 List<Source> sources = newSources({ |
| 1476 '/a.dart': ''' | 1714 '/a.dart': ''' |
| 1477 ''', | 1715 ''', |
| 1478 '/b.dart': ''' | 1716 '/b.dart': ''' |
| 1479 import 'a.dart'; | 1717 import 'a.dart'; |
| 1480 ''' | 1718 ''' |
| 1481 }); | 1719 }); |
| 1482 List<Map<ResultDescriptor, dynamic>> results = | 1720 List<Map<ResultDescriptor, dynamic>> results = |
| 1483 computeLibraryResultsMap(sources, LIBRARY_CYCLE); | 1721 computeLibraryResultsMap(sources, LIBRARY_CYCLE); |
| 1484 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; | 1722 List<LibraryElement> component0 = getLibraryCycle(results[0]); |
| 1485 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; | 1723 List<LibraryElement> component1 = getLibraryCycle(results[1]); |
| 1486 expect(component0, hasLength(1)); | 1724 expect(component0, hasLength(1)); |
| 1487 expect(component1, hasLength(1)); | 1725 expect(component1, hasLength(1)); |
| 1488 | 1726 |
| 1489 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; | 1727 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1490 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; | 1728 List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]); |
| 1491 expect(units0, hasLength(1)); | 1729 expect(units0, hasLength(1)); |
| 1492 expect(units1, hasLength(1)); | 1730 expect(units1, hasLength(1)); |
| 1493 | 1731 |
| 1494 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; | 1732 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1495 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; | 1733 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); |
| 1496 expect(dep0, hasLength(1)); // dart:core | 1734 expect(dep0, hasLength(1)); // dart:core |
| 1497 expect(dep1, hasLength(2)); // dart:core, a.dart | 1735 expect(dep1, hasLength(2)); // dart:core, a.dart |
| 1498 } | 1736 } |
| 1499 | 1737 |
| 1500 void test_library_cycle_loop() { | 1738 void test_library_cycle_loop() { |
| 1501 List<Source> sources = newSources({ | 1739 List<Source> sources = newSources({ |
| 1502 '/a.dart': ''' | 1740 '/a.dart': ''' |
| 1503 import 'c.dart'; | 1741 import 'c.dart'; |
| 1504 ''', | 1742 ''', |
| 1505 '/b.dart': ''' | 1743 '/b.dart': ''' |
| 1506 import 'a.dart'; | 1744 import 'a.dart'; |
| 1507 ''', | 1745 ''', |
| 1508 '/c.dart': ''' | 1746 '/c.dart': ''' |
| 1509 import 'b.dart'; | 1747 import 'b.dart'; |
| 1510 ''' | 1748 ''' |
| 1511 }); | 1749 }); |
| 1512 List<Map<ResultDescriptor, dynamic>> results = | 1750 List<Map<ResultDescriptor, dynamic>> results = |
| 1513 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); | 1751 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1514 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; | 1752 List<LibraryElement> component0 = getLibraryCycle(results[0]); |
| 1515 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; | 1753 List<LibraryElement> component1 = getLibraryCycle(results[1]); |
| 1516 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; | 1754 List<LibraryElement> component2 = getLibraryCycle(results[2]); |
| 1517 | 1755 |
| 1518 expect(component0, hasLength(3)); | 1756 expect(component0, hasLength(3)); |
| 1519 expect(component1, hasLength(3)); | 1757 expect(component1, hasLength(3)); |
| 1520 expect(component2, hasLength(3)); | 1758 expect(component2, hasLength(3)); |
| 1521 | 1759 |
| 1522 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; | 1760 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1523 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; | 1761 List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]); |
| 1524 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; | 1762 List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]); |
| 1525 expect(units0, hasLength(3)); | 1763 expect(units0, hasLength(3)); |
| 1526 expect(units1, hasLength(3)); | 1764 expect(units1, hasLength(3)); |
| 1527 expect(units2, hasLength(3)); | 1765 expect(units2, hasLength(3)); |
| 1528 | 1766 |
| 1529 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; | 1767 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1530 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; | 1768 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); |
| 1531 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; | 1769 List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]); |
| 1532 expect(dep0, hasLength(1)); // dart:core | 1770 expect(dep0, hasLength(1)); // dart:core |
| 1533 expect(dep1, hasLength(1)); // dart:core | 1771 expect(dep1, hasLength(1)); // dart:core |
| 1534 expect(dep2, hasLength(1)); // dart:core | 1772 expect(dep2, hasLength(1)); // dart:core |
| 1535 } | 1773 } |
| 1536 | 1774 |
| 1775 void test_library_cycle_override_inference_incremental() { |
| 1776 enableStrongMode(); |
| 1777 Source lib1Source = newSource( |
| 1778 '/my_lib1.dart', |
| 1779 ''' |
| 1780 library my_lib1; |
| 1781 import 'my_lib3.dart'; |
| 1782 '''); |
| 1783 Source lib2Source = newSource( |
| 1784 '/my_lib2.dart', |
| 1785 ''' |
| 1786 library my_lib2; |
| 1787 import 'my_lib1.dart'; |
| 1788 '''); |
| 1789 Source lib3Source = newSource( |
| 1790 '/my_lib3.dart', |
| 1791 ''' |
| 1792 library my_lib3; |
| 1793 import 'my_lib2.dart'; |
| 1794 |
| 1795 class A { |
| 1796 int foo(int x) => null; |
| 1797 } |
| 1798 class B extends A { |
| 1799 foo(x) => null; |
| 1800 } |
| 1801 '''); |
| 1802 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); |
| 1803 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); |
| 1804 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); |
| 1805 |
| 1806 computeResult(lib1Target, RESOLVED_UNIT); |
| 1807 computeResult(lib2Target, RESOLVED_UNIT); |
| 1808 computeResult(lib3Target, RESOLVED_UNIT); |
| 1809 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 1810 ClassElement b = unit.declarations[1].element; |
| 1811 expect(b.getMethod('foo').returnType.toString(), 'int'); |
| 1812 |
| 1813 // add a dummy edit. |
| 1814 context.setContents( |
| 1815 lib1Source, |
| 1816 ''' |
| 1817 library my_lib1; |
| 1818 import 'my_lib3.dart'; |
| 1819 var foo = 123; |
| 1820 '''); |
| 1821 _expectInvalid(lib1Source); |
| 1822 _expectInvalid(lib2Source); |
| 1823 _expectInvalid(lib3Source); |
| 1824 |
| 1825 computeResult(lib1Target, RESOLVED_UNIT); |
| 1826 computeResult(lib2Target, RESOLVED_UNIT); |
| 1827 computeResult(lib3Target, RESOLVED_UNIT); |
| 1828 unit = outputs[RESOLVED_UNIT]; |
| 1829 b = unit.declarations[1].element; |
| 1830 expect(b.getMethod('foo').returnType.toString(), 'int', |
| 1831 reason: 'edit should not affect member inference'); |
| 1832 } |
| 1833 |
| 1537 void test_library_cycle_self_loop() { | 1834 void test_library_cycle_self_loop() { |
| 1538 List<Source> sources = newSources({ | 1835 List<Source> sources = newSources({ |
| 1539 '/a.dart': ''' | 1836 '/a.dart': ''' |
| 1540 import 'a.dart'; | 1837 import 'a.dart'; |
| 1541 ''' | 1838 ''' |
| 1542 }); | 1839 }); |
| 1543 List<Map<ResultDescriptor, dynamic>> results = | 1840 List<Map<ResultDescriptor, dynamic>> results = |
| 1544 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); | 1841 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1545 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; | 1842 List<LibraryElement> component0 = getLibraryCycle(results[0]); |
| 1546 expect(component0, hasLength(1)); | 1843 expect(component0, hasLength(1)); |
| 1547 | 1844 |
| 1548 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; | 1845 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1549 expect(units0, hasLength(1)); | 1846 expect(units0, hasLength(1)); |
| 1550 | 1847 |
| 1551 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; | 1848 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1552 expect(dep0, hasLength(1)); // dart:core | 1849 expect(dep0, hasLength(1)); // dart:core |
| 1553 } | 1850 } |
| 1554 | 1851 |
| 1555 void test_library_cycle_singleton() { | 1852 void test_library_cycle_singleton() { |
| 1556 Source source = newSource( | 1853 Source source = newSource( |
| 1557 '/test.dart', | 1854 '/test.dart', |
| 1558 ''' | 1855 ''' |
| 1559 import 'dart:core'; | 1856 import 'dart:core'; |
| 1560 '''); | 1857 '''); |
| 1561 computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE); | 1858 computeResult(source, LIBRARY_CYCLE); |
| 1562 List<LibraryElement> component = outputs[LIBRARY_CYCLE]; | 1859 List<LibraryElement> component = getLibraryCycle(outputs); |
| 1563 List<CompilationUnitElement> units = outputs[LIBRARY_CYCLE_UNITS]; | 1860 List<LibrarySpecificUnit> units = getLibraryCycleUnits(outputs); |
| 1564 List<CompilationUnitElement> deps = outputs[LIBRARY_CYCLE_DEPENDENCIES]; | 1861 List<LibrarySpecificUnit> deps = getLibraryCycleDependencies(outputs); |
| 1565 expect(component, hasLength(1)); | 1862 expect(component, hasLength(1)); |
| 1566 expect(units, hasLength(1)); | 1863 expect(units, hasLength(1)); |
| 1567 expect(deps, hasLength(1)); | 1864 expect(deps, hasLength(1)); |
| 1568 } | 1865 } |
| 1569 | 1866 |
| 1570 void test_library_cycle_tree() { | 1867 void test_library_cycle_tree() { |
| 1571 List<Source> sources = newSources({ | 1868 List<Source> sources = newSources({ |
| 1572 '/a.dart': ''' | 1869 '/a.dart': ''' |
| 1573 ''', | 1870 ''', |
| 1574 '/b.dart': ''' | 1871 '/b.dart': ''' |
| 1575 ''', | 1872 ''', |
| 1576 '/c.dart': ''' | 1873 '/c.dart': ''' |
| 1577 import 'a.dart'; | 1874 import 'a.dart'; |
| 1578 import 'b.dart'; | 1875 import 'b.dart'; |
| 1579 ''' | 1876 ''' |
| 1580 }); | 1877 }); |
| 1581 List<Map<ResultDescriptor, dynamic>> results = | 1878 List<Map<ResultDescriptor, dynamic>> results = |
| 1582 computeLibraryResultsMap(sources, LIBRARY_CYCLE); | 1879 computeLibraryResultsMap(sources, LIBRARY_CYCLE); |
| 1583 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; | 1880 List<LibraryElement> component0 = getLibraryCycle(results[0]); |
| 1584 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; | 1881 List<LibraryElement> component1 = getLibraryCycle(results[1]); |
| 1585 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; | 1882 List<LibraryElement> component2 = getLibraryCycle(results[2]); |
| 1586 expect(component0, hasLength(1)); | 1883 expect(component0, hasLength(1)); |
| 1587 expect(component1, hasLength(1)); | 1884 expect(component1, hasLength(1)); |
| 1588 expect(component2, hasLength(1)); | 1885 expect(component2, hasLength(1)); |
| 1589 | 1886 |
| 1590 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; | 1887 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1591 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; | 1888 List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]); |
| 1592 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; | 1889 List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]); |
| 1593 expect(units0, hasLength(1)); | 1890 expect(units0, hasLength(1)); |
| 1594 expect(units1, hasLength(1)); | 1891 expect(units1, hasLength(1)); |
| 1595 expect(units2, hasLength(1)); | 1892 expect(units2, hasLength(1)); |
| 1596 | 1893 |
| 1597 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; | 1894 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1598 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; | 1895 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); |
| 1599 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; | 1896 List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]); |
| 1600 expect(dep0, hasLength(1)); // dart:core | 1897 expect(dep0, hasLength(1)); // dart:core |
| 1601 expect(dep1, hasLength(1)); // dart:core, | 1898 expect(dep1, hasLength(1)); // dart:core, |
| 1602 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart | 1899 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart |
| 1603 } | 1900 } |
| 1604 | 1901 |
| 1605 void test_library_double_loop() { | 1902 void test_library_double_loop() { |
| 1606 List<Source> sources = newSources({ | 1903 List<Source> sources = newSources({ |
| 1607 '/a.dart': ''' | 1904 '/a.dart': ''' |
| 1608 import 'b.dart'; | 1905 import 'b.dart'; |
| 1609 ''', | 1906 ''', |
| 1610 '/b.dart': ''' | 1907 '/b.dart': ''' |
| 1611 import 'a.dart'; | 1908 import 'a.dart'; |
| 1612 ''', | 1909 ''', |
| 1613 '/c.dart': ''' | 1910 '/c.dart': ''' |
| 1614 import 'd.dart' as foo; | 1911 import 'd.dart' as foo; |
| 1615 import 'a.dart' as bar; | 1912 import 'a.dart' as bar; |
| 1616 export 'b.dart'; | 1913 export 'b.dart'; |
| 1617 ''', | 1914 ''', |
| 1618 '/d.dart': ''' | 1915 '/d.dart': ''' |
| 1619 import 'c.dart' as foo; | 1916 import 'c.dart' as foo; |
| 1620 import 'b.dart' as bar; | 1917 import 'b.dart' as bar; |
| 1621 export 'a.dart'; | 1918 export 'a.dart'; |
| 1622 ''' | 1919 ''' |
| 1623 }); | 1920 }); |
| 1624 List<Map<ResultDescriptor, dynamic>> results = | 1921 List<Map<ResultDescriptor, dynamic>> results = |
| 1625 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); | 1922 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); |
| 1626 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; | 1923 List<LibraryElement> component0 = getLibraryCycle(results[0]); |
| 1627 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; | 1924 List<LibraryElement> component1 = getLibraryCycle(results[1]); |
| 1628 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; | 1925 List<LibraryElement> component2 = getLibraryCycle(results[2]); |
| 1629 List<LibraryElement> component3 = results[3][LIBRARY_CYCLE]; | 1926 List<LibraryElement> component3 = getLibraryCycle(results[3]); |
| 1630 | 1927 |
| 1631 expect(component0, hasLength(2)); | 1928 expect(component0, hasLength(2)); |
| 1632 expect(component1, hasLength(2)); | 1929 expect(component1, hasLength(2)); |
| 1633 expect(component2, hasLength(2)); | 1930 expect(component2, hasLength(2)); |
| 1634 expect(component3, hasLength(2)); | 1931 expect(component3, hasLength(2)); |
| 1635 | 1932 |
| 1636 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; | 1933 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1637 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; | 1934 List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results[1]); |
| 1638 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; | 1935 List<LibrarySpecificUnit> units2 = getLibraryCycleUnits(results[2]); |
| 1639 List<CompilationUnitElement> units3 = results[3][LIBRARY_CYCLE_UNITS]; | 1936 List<LibrarySpecificUnit> units3 = getLibraryCycleUnits(results[3]); |
| 1640 expect(units0, hasLength(2)); | 1937 expect(units0, hasLength(2)); |
| 1641 expect(units1, hasLength(2)); | 1938 expect(units1, hasLength(2)); |
| 1642 expect(units2, hasLength(2)); | 1939 expect(units2, hasLength(2)); |
| 1643 expect(units3, hasLength(2)); | 1940 expect(units3, hasLength(2)); |
| 1644 | 1941 |
| 1645 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; | 1942 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1646 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; | 1943 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); |
| 1647 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; | 1944 List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]); |
| 1648 List<CompilationUnitElement> dep3 = results[3][LIBRARY_CYCLE_DEPENDENCIES]; | 1945 List<LibrarySpecificUnit> dep3 = getLibraryCycleDependencies(results[3]); |
| 1649 expect(dep0, hasLength(1)); // dart:core | 1946 expect(dep0, hasLength(1)); // dart:core |
| 1650 expect(dep1, hasLength(1)); // dart:core | 1947 expect(dep1, hasLength(1)); // dart:core |
| 1651 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart | 1948 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart |
| 1652 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart | 1949 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart |
| 1653 } | 1950 } |
| 1654 | 1951 |
| 1655 void test_library_double_loop_parts() { | 1952 void test_library_double_loop_parts() { |
| 1656 List<Source> sources = newSources({ | 1953 List<Source> sources = newSources({ |
| 1657 '/a.dart': ''' | 1954 '/a.dart': ''' |
| 1658 import 'b.dart'; | 1955 import 'b.dart'; |
| 1659 part 'aa.dart'; | 1956 part 'aa.dart'; |
| 1660 part 'ab.dart'; | 1957 part 'ab.dart'; |
| 1661 ''', | 1958 ''', |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1676 import 'b.dart' as bar; | 1973 import 'b.dart' as bar; |
| 1677 export 'a.dart'; | 1974 export 'a.dart'; |
| 1678 part 'da.dart'; | 1975 part 'da.dart'; |
| 1679 part 'db.dart'; | 1976 part 'db.dart'; |
| 1680 ''', | 1977 ''', |
| 1681 '/da.dart': ''' | 1978 '/da.dart': ''' |
| 1682 ''', | 1979 ''', |
| 1683 '/db.dart': ''' | 1980 '/db.dart': ''' |
| 1684 ''' | 1981 ''' |
| 1685 }); | 1982 }); |
| 1686 computeResult( | 1983 computeResult(sources[0], LIBRARY_CYCLE); |
| 1687 new LibrarySpecificUnit(sources[0], sources[0]), LIBRARY_CYCLE); | |
| 1688 Map<ResultDescriptor, dynamic> results0 = outputs; | 1984 Map<ResultDescriptor, dynamic> results0 = outputs; |
| 1689 computeResult( | 1985 computeResult(sources[1], LIBRARY_CYCLE); |
| 1690 new LibrarySpecificUnit(sources[1], sources[1]), LIBRARY_CYCLE); | |
| 1691 Map<ResultDescriptor, dynamic> results1 = outputs; | 1986 Map<ResultDescriptor, dynamic> results1 = outputs; |
| 1692 computeResult( | 1987 computeResult(sources[4], LIBRARY_CYCLE); |
| 1693 new LibrarySpecificUnit(sources[0], sources[2]), LIBRARY_CYCLE); | |
| 1694 Map<ResultDescriptor, dynamic> results2 = outputs; | |
| 1695 computeResult( | |
| 1696 new LibrarySpecificUnit(sources[0], sources[3]), LIBRARY_CYCLE); | |
| 1697 Map<ResultDescriptor, dynamic> results3 = outputs; | |
| 1698 computeResult( | |
| 1699 new LibrarySpecificUnit(sources[4], sources[4]), LIBRARY_CYCLE); | |
| 1700 Map<ResultDescriptor, dynamic> results4 = outputs; | 1988 Map<ResultDescriptor, dynamic> results4 = outputs; |
| 1701 computeResult( | 1989 computeResult(sources[5], LIBRARY_CYCLE); |
| 1702 new LibrarySpecificUnit(sources[5], sources[5]), LIBRARY_CYCLE); | |
| 1703 Map<ResultDescriptor, dynamic> results5 = outputs; | 1990 Map<ResultDescriptor, dynamic> results5 = outputs; |
| 1704 computeResult( | |
| 1705 new LibrarySpecificUnit(sources[5], sources[6]), LIBRARY_CYCLE); | |
| 1706 Map<ResultDescriptor, dynamic> results6 = outputs; | |
| 1707 computeResult( | |
| 1708 new LibrarySpecificUnit(sources[5], sources[7]), LIBRARY_CYCLE); | |
| 1709 Map<ResultDescriptor, dynamic> results7 = outputs; | |
| 1710 | 1991 |
| 1711 List<LibraryElement> component0 = results0[LIBRARY_CYCLE]; | 1992 List<LibraryElement> component0 = getLibraryCycle(results0); |
| 1712 List<LibraryElement> component1 = results1[LIBRARY_CYCLE]; | 1993 List<LibraryElement> component1 = getLibraryCycle(results1); |
| 1713 List<LibraryElement> component2 = results2[LIBRARY_CYCLE]; | 1994 List<LibraryElement> component4 = getLibraryCycle(results4); |
| 1714 List<LibraryElement> component3 = results3[LIBRARY_CYCLE]; | 1995 List<LibraryElement> component5 = getLibraryCycle(results5); |
| 1715 List<LibraryElement> component4 = results4[LIBRARY_CYCLE]; | |
| 1716 List<LibraryElement> component5 = results5[LIBRARY_CYCLE]; | |
| 1717 List<LibraryElement> component6 = results6[LIBRARY_CYCLE]; | |
| 1718 List<LibraryElement> component7 = results7[LIBRARY_CYCLE]; | |
| 1719 | 1996 |
| 1720 expect(component0, hasLength(2)); | 1997 expect(component0, hasLength(2)); |
| 1721 expect(component1, hasLength(2)); | 1998 expect(component1, hasLength(2)); |
| 1722 expect(component2, hasLength(2)); | |
| 1723 expect(component3, hasLength(2)); | |
| 1724 expect(component4, hasLength(2)); | 1999 expect(component4, hasLength(2)); |
| 1725 expect(component5, hasLength(2)); | 2000 expect(component5, hasLength(2)); |
| 1726 expect(component6, hasLength(2)); | |
| 1727 expect(component7, hasLength(2)); | |
| 1728 | 2001 |
| 1729 List<CompilationUnitElement> units0 = results0[LIBRARY_CYCLE_UNITS]; | 2002 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results0); |
| 1730 List<CompilationUnitElement> units1 = results1[LIBRARY_CYCLE_UNITS]; | 2003 List<LibrarySpecificUnit> units1 = getLibraryCycleUnits(results1); |
| 1731 List<CompilationUnitElement> units2 = results2[LIBRARY_CYCLE_UNITS]; | 2004 List<LibrarySpecificUnit> units4 = getLibraryCycleUnits(results4); |
| 1732 List<CompilationUnitElement> units3 = results3[LIBRARY_CYCLE_UNITS]; | 2005 List<LibrarySpecificUnit> units5 = getLibraryCycleUnits(results5); |
| 1733 List<CompilationUnitElement> units4 = results4[LIBRARY_CYCLE_UNITS]; | |
| 1734 List<CompilationUnitElement> units5 = results5[LIBRARY_CYCLE_UNITS]; | |
| 1735 List<CompilationUnitElement> units6 = results6[LIBRARY_CYCLE_UNITS]; | |
| 1736 List<CompilationUnitElement> units7 = results7[LIBRARY_CYCLE_UNITS]; | |
| 1737 expect(units0, hasLength(4)); | 2006 expect(units0, hasLength(4)); |
| 1738 expect(units1, hasLength(4)); | 2007 expect(units1, hasLength(4)); |
| 1739 expect(units2, hasLength(4)); | |
| 1740 expect(units3, hasLength(4)); | |
| 1741 expect(units4, hasLength(4)); | 2008 expect(units4, hasLength(4)); |
| 1742 expect(units5, hasLength(4)); | 2009 expect(units5, hasLength(4)); |
| 1743 expect(units6, hasLength(4)); | |
| 1744 expect(units7, hasLength(4)); | |
| 1745 | 2010 |
| 1746 List<CompilationUnitElement> dep0 = results0[LIBRARY_CYCLE_DEPENDENCIES]; | 2011 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results0); |
| 1747 List<CompilationUnitElement> dep1 = results1[LIBRARY_CYCLE_DEPENDENCIES]; | 2012 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results1); |
| 1748 List<CompilationUnitElement> dep2 = results2[LIBRARY_CYCLE_DEPENDENCIES]; | 2013 List<LibrarySpecificUnit> dep4 = getLibraryCycleDependencies(results4); |
| 1749 List<CompilationUnitElement> dep3 = results3[LIBRARY_CYCLE_DEPENDENCIES]; | 2014 List<LibrarySpecificUnit> dep5 = getLibraryCycleDependencies(results5); |
| 1750 List<CompilationUnitElement> dep4 = results4[LIBRARY_CYCLE_DEPENDENCIES]; | |
| 1751 List<CompilationUnitElement> dep5 = results5[LIBRARY_CYCLE_DEPENDENCIES]; | |
| 1752 List<CompilationUnitElement> dep6 = results6[LIBRARY_CYCLE_DEPENDENCIES]; | |
| 1753 List<CompilationUnitElement> dep7 = results7[LIBRARY_CYCLE_DEPENDENCIES]; | |
| 1754 expect(dep0, hasLength(1)); // dart:core | 2015 expect(dep0, hasLength(1)); // dart:core |
| 1755 expect(dep1, hasLength(1)); // dart:core | 2016 expect(dep1, hasLength(1)); // dart:core |
| 1756 expect(dep2, hasLength(1)); // dart:core | |
| 1757 expect(dep3, hasLength(1)); // dart:core | |
| 1758 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2017 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1759 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2018 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
| 1760 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2019 } |
| 1761 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2020 |
| 2021 void _assertLibraryCycle(Source source, List<Source> expected) { |
| 2022 computeResult(source, LIBRARY_CYCLE); |
| 2023 List<LibraryElement> cycle = outputs[LIBRARY_CYCLE] as List<LibraryElement>; |
| 2024 expect(cycle.map((e) => e.source), unorderedEquals(expected)); |
| 2025 } |
| 2026 |
| 2027 void _expectInvalid(Source librarySource) { |
| 2028 CacheEntry entry = context.getCacheEntry(librarySource); |
| 2029 expect(entry.getState(LIBRARY_CYCLE), CacheState.INVALID); |
| 1762 } | 2030 } |
| 1763 } | 2031 } |
| 1764 | 2032 |
| 1765 @reflectiveTest | 2033 @reflectiveTest |
| 1766 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { | 2034 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { |
| 2035 List<Source> getContainingLibraries(Map<ResultDescriptor, dynamic> outputs) { |
| 2036 return outputs[CONTAINING_LIBRARIES] as List<Source>; |
| 2037 } |
| 2038 |
| 1767 test_perform_definingCompilationUnit() { | 2039 test_perform_definingCompilationUnit() { |
| 1768 AnalysisTarget library = newSource('/test.dart', 'library test;'); | 2040 AnalysisTarget library = newSource('/test.dart', 'library test;'); |
| 1769 computeResult(library, INCLUDED_PARTS); | 2041 computeResult(library, INCLUDED_PARTS); |
| 1770 computeResult(library, CONTAINING_LIBRARIES, | 2042 computeResult(library, CONTAINING_LIBRARIES, |
| 1771 matcher: isContainingLibrariesTask); | 2043 matcher: isContainingLibrariesTask); |
| 1772 expect(outputs, hasLength(1)); | 2044 expect(outputs, hasLength(1)); |
| 1773 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 2045 List<Source> containingLibraries = getContainingLibraries(outputs); |
| 1774 expect(containingLibraries, unorderedEquals([library])); | 2046 expect(containingLibraries, unorderedEquals([library])); |
| 1775 } | 2047 } |
| 1776 | 2048 |
| 1777 test_perform_partInMultipleLibraries() { | 2049 test_perform_partInMultipleLibraries() { |
| 1778 AnalysisTarget library1 = | 2050 AnalysisTarget library1 = |
| 1779 newSource('/lib1.dart', 'library test; part "part.dart";'); | 2051 newSource('/lib1.dart', 'library test; part "part.dart";'); |
| 1780 AnalysisTarget library2 = | 2052 AnalysisTarget library2 = |
| 1781 newSource('/lib2.dart', 'library test; part "part.dart";'); | 2053 newSource('/lib2.dart', 'library test; part "part.dart";'); |
| 1782 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 2054 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 1783 computeResult(library1, INCLUDED_PARTS); | 2055 computeResult(library1, INCLUDED_PARTS); |
| 1784 computeResult(library2, INCLUDED_PARTS); | 2056 computeResult(library2, INCLUDED_PARTS); |
| 1785 computeResult(part, SOURCE_KIND); | 2057 computeResult(part, SOURCE_KIND); |
| 1786 computeResult(part, CONTAINING_LIBRARIES, | 2058 computeResult(part, CONTAINING_LIBRARIES, |
| 1787 matcher: isContainingLibrariesTask); | 2059 matcher: isContainingLibrariesTask); |
| 1788 expect(outputs, hasLength(1)); | 2060 expect(outputs, hasLength(1)); |
| 1789 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 2061 List<Source> containingLibraries = getContainingLibraries(outputs); |
| 1790 expect(containingLibraries, unorderedEquals([library1, library2])); | 2062 expect(containingLibraries, unorderedEquals([library1, library2])); |
| 1791 } | 2063 } |
| 1792 | 2064 |
| 1793 test_perform_partInSingleLibrary() { | 2065 test_perform_partInSingleLibrary() { |
| 1794 AnalysisTarget library = | 2066 AnalysisTarget library = |
| 1795 newSource('/lib.dart', 'library test; part "part.dart";'); | 2067 newSource('/lib.dart', 'library test; part "part.dart";'); |
| 1796 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 2068 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 1797 computeResult(library, INCLUDED_PARTS); | 2069 computeResult(library, INCLUDED_PARTS); |
| 1798 computeResult(part, SOURCE_KIND); | 2070 computeResult(part, SOURCE_KIND); |
| 1799 computeResult(part, CONTAINING_LIBRARIES, | 2071 computeResult(part, CONTAINING_LIBRARIES, |
| 1800 matcher: isContainingLibrariesTask); | 2072 matcher: isContainingLibrariesTask); |
| 1801 expect(outputs, hasLength(1)); | 2073 expect(outputs, hasLength(1)); |
| 1802 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 2074 List<Source> containingLibraries = getContainingLibraries(outputs); |
| 1803 expect(containingLibraries, unorderedEquals([library])); | 2075 expect(containingLibraries, unorderedEquals([library])); |
| 1804 } | 2076 } |
| 1805 } | 2077 } |
| 1806 | 2078 |
| 1807 @reflectiveTest | 2079 @reflectiveTest |
| 1808 class DartErrorsTaskTest extends _AbstractDartTaskTest { | 2080 class DartErrorsTaskTest extends _AbstractDartTaskTest { |
| 2081 List<AnalysisError> getDartErrors(Map<ResultDescriptor, dynamic> outputs) { |
| 2082 return outputs[DART_ERRORS] as List<AnalysisError>; |
| 2083 } |
| 2084 |
| 1809 test_perform_definingCompilationUnit() { | 2085 test_perform_definingCompilationUnit() { |
| 1810 AnalysisTarget library = | 2086 AnalysisTarget library = |
| 1811 newSource('/test.dart', 'library test; import "dart:math";'); | 2087 newSource('/test.dart', 'library test; import "dart:math";'); |
| 1812 computeResult(library, INCLUDED_PARTS); | 2088 computeResult(library, INCLUDED_PARTS); |
| 1813 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); | 2089 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); |
| 1814 expect(outputs, hasLength(1)); | 2090 expect(outputs, hasLength(1)); |
| 1815 List<AnalysisError> errors = outputs[DART_ERRORS]; | 2091 List<AnalysisError> errors = getDartErrors(outputs); |
| 1816 expect(errors, hasLength(1)); | 2092 expect(errors, hasLength(1)); |
| 1817 } | 2093 } |
| 1818 | 2094 |
| 1819 test_perform_partInSingleLibrary() { | 2095 test_perform_partInSingleLibrary() { |
| 1820 AnalysisTarget library = newSource( | 2096 AnalysisTarget library = newSource( |
| 1821 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); | 2097 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); |
| 1822 AnalysisTarget part = | 2098 AnalysisTarget part = |
| 1823 newSource('/part.dart', 'part of test; class A extends A {}'); | 2099 newSource('/part.dart', 'part of test; class A extends A {}'); |
| 1824 computeResult(library, INCLUDED_PARTS); | 2100 computeResult(library, INCLUDED_PARTS); |
| 1825 computeResult(library, DART_ERRORS); | 2101 computeResult(library, DART_ERRORS); |
| 1826 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask); | 2102 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask); |
| 1827 expect(outputs, hasLength(1)); | 2103 expect(outputs, hasLength(1)); |
| 1828 List<AnalysisError> errors = outputs[DART_ERRORS]; | 2104 List<AnalysisError> errors = getDartErrors(outputs); |
| 1829 // This should contain only the errors in the part file, not the ones in the | 2105 // This should contain only the errors in the part file, not the ones in the |
| 1830 // library. | 2106 // library. |
| 1831 expect(errors, hasLength(1)); | 2107 expect(errors, hasLength(1)); |
| 1832 } | 2108 } |
| 1833 } | 2109 } |
| 1834 | 2110 |
| 1835 @reflectiveTest | 2111 @reflectiveTest |
| 1836 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { | 2112 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { |
| 2113 test_created_resolved_unit() { |
| 2114 Source source = newSource( |
| 2115 '/test.dart', |
| 2116 r''' |
| 2117 library lib; |
| 2118 class A {} |
| 2119 '''); |
| 2120 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2121 computeResult(target, RESOLVED_UNIT12); |
| 2122 expect(outputs[RESOLVED_UNIT12], isNotNull); |
| 2123 expect(outputs[CREATED_RESOLVED_UNIT12], isTrue); |
| 2124 } |
| 2125 |
| 1837 test_perform() { | 2126 test_perform() { |
| 1838 Source source = newSource( | 2127 Source source = newSource( |
| 1839 '/test.dart', | 2128 '/test.dart', |
| 1840 ''' | 2129 ''' |
| 1841 class C { | 2130 class C { |
| 1842 const C(); | 2131 const C(); |
| 1843 } | 2132 } |
| 1844 | 2133 |
| 1845 @x | 2134 @x |
| 1846 f() {} | 2135 f() {} |
| 1847 | 2136 |
| 1848 const x = const C(); | 2137 const x = const C(); |
| 1849 '''); | 2138 '''); |
| 1850 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2139 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1851 computeResult(target, RESOLVED_UNIT10, | 2140 computeResult(target, RESOLVED_UNIT12, |
| 1852 matcher: isEvaluateUnitConstantsTask); | 2141 matcher: isEvaluateUnitConstantsTask); |
| 1853 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 2142 CompilationUnit unit = outputs[RESOLVED_UNIT12]; |
| 1854 CompilationUnitElement unitElement = unit.element; | 2143 CompilationUnitElement unitElement = unit.element; |
| 1855 expect( | 2144 expect( |
| 1856 (unitElement.types[0].constructors[0] as ConstructorElementImpl) | 2145 (unitElement.types[0].constructors[0] as ConstructorElementImpl) |
| 1857 .isCycleFree, | 2146 .isCycleFree, |
| 1858 isTrue); | 2147 isTrue); |
| 1859 expect( | 2148 expect( |
| 1860 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) | 2149 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) |
| 1861 .evaluationResult, | 2150 .evaluationResult, |
| 1862 isNotNull); | 2151 isNotNull); |
| 1863 expect( | 2152 expect( |
| 1864 (unitElement.topLevelVariables[0] as TopLevelVariableElementImpl) | 2153 (unitElement.topLevelVariables[0] as TopLevelVariableElementImpl) |
| 1865 .evaluationResult, | 2154 .evaluationResult, |
| 1866 isNotNull); | 2155 isNotNull); |
| 1867 } | 2156 } |
| 1868 } | 2157 } |
| 1869 | 2158 |
| 1870 @reflectiveTest | 2159 @reflectiveTest |
| 1871 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { | 2160 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { |
| 1872 UsedImportedElements usedElements; | 2161 UsedImportedElements usedElements; |
| 1873 Set<String> usedElementNames; | 2162 Set<String> usedElementNames; |
| 1874 | 2163 |
| 1875 test_perform() { | 2164 test_perform_inBody() { |
| 1876 newSource( | 2165 newSource( |
| 1877 '/a.dart', | 2166 '/a.dart', |
| 1878 r''' | 2167 r''' |
| 1879 library lib_a; | 2168 library lib_a; |
| 1880 class A {} | 2169 class A {} |
| 1881 '''); | 2170 '''); |
| 1882 newSource( | 2171 newSource( |
| 1883 '/b.dart', | 2172 '/b.dart', |
| 1884 r''' | 2173 r''' |
| 1885 library lib_b; | 2174 library lib_b; |
| 1886 class B {} | 2175 class B {} |
| 1887 '''); | 2176 '''); |
| 1888 Source source = newSource( | 2177 Source source = newSource( |
| 1889 '/test.dart', | 2178 '/test.dart', |
| 1890 r''' | 2179 r''' |
| 1891 import 'a.dart'; | 2180 import 'a.dart'; |
| 1892 import 'b.dart'; | 2181 import 'b.dart'; |
| 1893 main() { | 2182 main() { |
| 1894 new A(); | 2183 new A(); |
| 1895 }'''); | 2184 }'''); |
| 1896 _computeUsedElements(source); | 2185 _computeUsedElements(source); |
| 1897 // validate | 2186 // validate |
| 1898 expect(usedElementNames, unorderedEquals(['A'])); | 2187 expect(usedElementNames, unorderedEquals(['A'])); |
| 1899 } | 2188 } |
| 1900 | 2189 |
| 2190 test_perform_inComment_exportDirective() { |
| 2191 Source source = newSource( |
| 2192 '/test.dart', |
| 2193 r''' |
| 2194 import 'dart:async'; |
| 2195 /// Use [Future]. |
| 2196 export 'dart:math'; |
| 2197 '''); |
| 2198 _computeUsedElements(source); |
| 2199 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2200 } |
| 2201 |
| 2202 test_perform_inComment_importDirective() { |
| 2203 Source source = newSource( |
| 2204 '/test.dart', |
| 2205 r''' |
| 2206 import 'dart:async'; |
| 2207 /// Use [Future]. |
| 2208 import 'dart:math'; |
| 2209 '''); |
| 2210 _computeUsedElements(source); |
| 2211 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2212 } |
| 2213 |
| 2214 test_perform_inComment_libraryDirective() { |
| 2215 Source source = newSource( |
| 2216 '/test.dart', |
| 2217 r''' |
| 2218 /// Use [Future]. |
| 2219 library test; |
| 2220 import 'dart:async'; |
| 2221 '''); |
| 2222 _computeUsedElements(source); |
| 2223 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2224 } |
| 2225 |
| 2226 test_perform_inComment_topLevelFunction() { |
| 2227 Source source = newSource( |
| 2228 '/test.dart', |
| 2229 r''' |
| 2230 import 'dart:async'; |
| 2231 /// Use [Future]. |
| 2232 main() {} |
| 2233 '''); |
| 2234 _computeUsedElements(source); |
| 2235 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2236 } |
| 2237 |
| 1901 void _computeUsedElements(Source source) { | 2238 void _computeUsedElements(Source source) { |
| 1902 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2239 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1903 computeResult(target, USED_IMPORTED_ELEMENTS, | 2240 computeResult(target, USED_IMPORTED_ELEMENTS, |
| 1904 matcher: isGatherUsedImportedElementsTask); | 2241 matcher: isGatherUsedImportedElementsTask); |
| 1905 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 2242 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 1906 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 2243 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1907 } | 2244 } |
| 1908 } | 2245 } |
| 1909 | 2246 |
| 1910 @reflectiveTest | 2247 @reflectiveTest |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2286 visitClassDeclaration(ClassDeclaration node) { | 2623 visitClassDeclaration(ClassDeclaration node) { |
| 2287 if (!new RegExp(r'^([_]*)([A-Z]+[a-z0-9]*)+$') | 2624 if (!new RegExp(r'^([_]*)([A-Z]+[a-z0-9]*)+$') |
| 2288 .hasMatch(node.name.toString())) { | 2625 .hasMatch(node.name.toString())) { |
| 2289 linter.reporter.reportErrorForNode(_testLintCode, node, []); | 2626 linter.reporter.reportErrorForNode(_testLintCode, node, []); |
| 2290 } | 2627 } |
| 2291 } | 2628 } |
| 2292 } | 2629 } |
| 2293 | 2630 |
| 2294 class GenerateLintsTaskTest_TestLinter extends Linter { | 2631 class GenerateLintsTaskTest_TestLinter extends Linter { |
| 2295 @override | 2632 @override |
| 2633 String get name => 'GenerateLintsTaskTest_TestLinter'; |
| 2634 |
| 2635 @override |
| 2296 AstVisitor getVisitor() => new GenerateLintsTaskTest_AstVisitor(this); | 2636 AstVisitor getVisitor() => new GenerateLintsTaskTest_AstVisitor(this); |
| 2297 } | 2637 } |
| 2298 | 2638 |
| 2299 @reflectiveTest | 2639 @reflectiveTest |
| 2300 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { | 2640 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { |
| 2641 test_created_resolved_unit() { |
| 2642 Source source = newSource( |
| 2643 '/test.dart', |
| 2644 r''' |
| 2645 library lib; |
| 2646 class A {} |
| 2647 '''); |
| 2648 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2649 computeResult(target, RESOLVED_UNIT10); |
| 2650 expect(outputs[RESOLVED_UNIT10], isNotNull); |
| 2651 expect(outputs[CREATED_RESOLVED_UNIT10], isTrue); |
| 2652 } |
| 2653 |
| 2301 void test_perform() { | 2654 void test_perform() { |
| 2302 enableStrongMode(); | 2655 enableStrongMode(); |
| 2303 AnalysisTarget source = newSource( | 2656 AnalysisTarget source = newSource( |
| 2304 '/test.dart', | 2657 '/test.dart', |
| 2305 ''' | 2658 ''' |
| 2306 class A { | 2659 class A { |
| 2307 X f; | 2660 X f; |
| 2308 Y m(Z x) {} | 2661 Y m(Z x) {} |
| 2309 } | 2662 } |
| 2310 class B extends A { | 2663 class B extends A { |
| 2311 var f; | 2664 var f; |
| 2312 m(x) {} | 2665 m(x) {} |
| 2313 } | 2666 } |
| 2314 class X {} | 2667 class X {} |
| 2315 class Y {} | 2668 class Y {} |
| 2316 class Z {} | 2669 class Z {} |
| 2317 '''); | 2670 '''); |
| 2318 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, | 2671 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10, |
| 2319 matcher: isInferInstanceMembersInUnitTask); | 2672 matcher: isInferInstanceMembersInUnitTask); |
| 2320 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2673 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 2321 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); | 2674 VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f'); |
| 2322 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); | 2675 MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm'); |
| 2323 DartType typeX = getClass(unit, 'X').element.type; | 2676 DartType typeX = AstFinder.getClass(unit, 'X').element.type; |
| 2324 DartType typeY = getClass(unit, 'Y').element.type; | 2677 DartType typeY = AstFinder.getClass(unit, 'Y').element.type; |
| 2325 DartType typeZ = getClass(unit, 'Z').element.type; | 2678 DartType typeZ = AstFinder.getClass(unit, 'Z').element.type; |
| 2326 | 2679 |
| 2327 expect(field.element.type, typeX); | 2680 expect(field.element.type, typeX); |
| 2328 expect(method.element.returnType, typeY); | 2681 expect(method.element.returnType, typeY); |
| 2329 expect(method.element.parameters[0].type, typeZ); | 2682 expect(method.element.parameters[0].type, typeZ); |
| 2330 } | 2683 } |
| 2331 | 2684 |
| 2332 void test_perform_cross_library_const() { | 2685 void test_perform_cross_library_const() { |
| 2333 enableStrongMode(); | 2686 enableStrongMode(); |
| 2334 AnalysisTarget firstSource = newSource( | 2687 AnalysisTarget firstSource = newSource( |
| 2335 '/first.dart', | 2688 '/first.dart', |
| 2336 ''' | 2689 ''' |
| 2337 library first; | 2690 library first; |
| 2338 | 2691 |
| 2339 const a = 'hello'; | 2692 const a = 'hello'; |
| 2340 '''); | 2693 '''); |
| 2341 AnalysisTarget secondSource = newSource( | 2694 AnalysisTarget secondSource = newSource( |
| 2342 '/second.dart', | 2695 '/second.dart', |
| 2343 ''' | 2696 ''' |
| 2344 import 'first.dart'; | 2697 import 'first.dart'; |
| 2345 | 2698 |
| 2346 const b = a; | 2699 const b = a; |
| 2347 class M { | 2700 class M { |
| 2348 String c = a; | 2701 String c = a; |
| 2349 } | 2702 } |
| 2350 '''); | 2703 '''); |
| 2351 computeResult( | 2704 computeResult( |
| 2352 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, | 2705 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10, |
| 2353 matcher: isInferInstanceMembersInUnitTask); | 2706 matcher: isInferInstanceMembersInUnitTask); |
| 2354 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; | 2707 CompilationUnit firstUnit = outputs[RESOLVED_UNIT10]; |
| 2355 computeResult( | 2708 computeResult( |
| 2356 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); | 2709 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); |
| 2357 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8]; | 2710 CompilationUnit secondUnit = outputs[RESOLVED_UNIT10]; |
| 2358 | 2711 |
| 2359 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2712 VariableDeclaration variableA = |
| 2360 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2713 AstFinder.getTopLevelVariable(firstUnit, 'a'); |
| 2361 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); | 2714 VariableDeclaration variableB = |
| 2715 AstFinder.getTopLevelVariable(secondUnit, 'b'); |
| 2716 VariableDeclaration variableC = |
| 2717 AstFinder.getFieldInClass(secondUnit, 'M', 'c'); |
| 2362 InterfaceType stringType = context.typeProvider.stringType; | 2718 InterfaceType stringType = context.typeProvider.stringType; |
| 2363 | 2719 |
| 2364 expect(variableA.element.type, stringType); | 2720 expect(variableA.element.type, stringType); |
| 2365 expect(variableB.element.type, stringType); | 2721 expect(variableB.element.type, stringType); |
| 2366 expect(variableB.initializer.staticType, stringType); | 2722 expect(variableB.initializer.staticType, stringType); |
| 2367 expect(variableC.element.type, stringType); | 2723 expect(variableC.element.type, stringType); |
| 2368 expect(variableC.initializer.staticType, stringType); | 2724 expect(variableC.initializer.staticType, stringType); |
| 2369 } | 2725 } |
| 2370 | 2726 |
| 2371 void test_perform_reresolution() { | 2727 void test_perform_reresolution() { |
| 2372 enableStrongMode(); | 2728 enableStrongMode(); |
| 2373 AnalysisTarget source = newSource( | 2729 AnalysisTarget source = newSource( |
| 2374 '/test.dart', | 2730 '/test.dart', |
| 2375 ''' | 2731 ''' |
| 2376 const topLevel = ''; | 2732 const topLevel = ''; |
| 2377 class C { | 2733 class C { |
| 2378 String field = topLevel; | 2734 String field = topLevel; |
| 2379 } | 2735 } |
| 2380 '''); | 2736 '''); |
| 2381 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); | 2737 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 2382 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2738 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 2383 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); | 2739 VariableDeclaration topLevelDecl = |
| 2384 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); | 2740 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2741 VariableDeclaration fieldDecl = |
| 2742 AstFinder.getFieldInClass(unit, 'C', 'field'); |
| 2385 VariableElement topLevel = topLevelDecl.name.staticElement; | 2743 VariableElement topLevel = topLevelDecl.name.staticElement; |
| 2386 VariableElement field = fieldDecl.name.staticElement; | 2744 VariableElement field = fieldDecl.name.staticElement; |
| 2387 | 2745 |
| 2388 InterfaceType stringType = context.typeProvider.stringType; | 2746 InterfaceType stringType = context.typeProvider.stringType; |
| 2389 expect(topLevel.type, stringType); | 2747 expect(topLevel.type, stringType); |
| 2390 expect(field.type, stringType); | 2748 expect(field.type, stringType); |
| 2391 expect(fieldDecl.initializer.staticType, stringType); | 2749 expect(fieldDecl.initializer.staticType, stringType); |
| 2392 } | 2750 } |
| 2393 } | 2751 } |
| 2394 | 2752 |
| 2395 @reflectiveTest | 2753 @reflectiveTest |
| 2396 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { | 2754 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { |
| 2755 @override |
| 2756 void setUp() { |
| 2757 super.setUp(); |
| 2758 enableStrongMode(); |
| 2759 } |
| 2760 |
| 2761 test_created_resolved_unit() { |
| 2762 Source source = newSource( |
| 2763 '/test.dart', |
| 2764 r''' |
| 2765 library lib; |
| 2766 class A {} |
| 2767 '''); |
| 2768 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2769 computeResult(target, RESOLVED_UNIT8); |
| 2770 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2771 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2772 } |
| 2773 |
| 2397 void test_perform_const_field() { | 2774 void test_perform_const_field() { |
| 2398 enableStrongMode(); | 2775 enableStrongMode(); |
| 2399 AnalysisTarget source = newSource( | 2776 AnalysisTarget source = newSource( |
| 2400 '/test.dart', | 2777 '/test.dart', |
| 2401 ''' | 2778 ''' |
| 2402 class M { | 2779 class M { |
| 2403 static const X = ""; | 2780 static const X = ""; |
| 2404 } | 2781 } |
| 2405 '''); | 2782 '''); |
| 2406 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, | 2783 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2407 matcher: isInferStaticVariableTypesInUnitTask); | 2784 matcher: isInferStaticVariableTypesInUnitTask); |
| 2408 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2785 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2409 VariableDeclaration declaration = getFieldInClass(unit, 'M', 'X'); | 2786 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); |
| 2410 InterfaceType stringType = context.typeProvider.stringType; | 2787 InterfaceType stringType = context.typeProvider.stringType; |
| 2411 expect(declaration.element.type, stringType); | 2788 expect(declaration.element.type, stringType); |
| 2412 } | 2789 } |
| 2413 | 2790 |
| 2791 test_perform_hasParseError() { |
| 2792 Source source = newSource( |
| 2793 '/test.dart', |
| 2794 r''' |
| 2795 @(i $= |
| 2796 '''); |
| 2797 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2798 computeResult(target, RESOLVED_UNIT8); |
| 2799 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2800 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2801 } |
| 2802 |
| 2414 void test_perform_nestedDeclarations() { | 2803 void test_perform_nestedDeclarations() { |
| 2415 enableStrongMode(); | 2804 enableStrongMode(); |
| 2416 AnalysisTarget source = newSource( | 2805 AnalysisTarget source = newSource( |
| 2417 '/test.dart', | 2806 '/test.dart', |
| 2418 ''' | 2807 ''' |
| 2419 var f = (int x) { | 2808 var f = (int x) { |
| 2420 int squared(int value) => value * value; | 2809 int squared(int value) => value * value; |
| 2421 var xSquared = squared(x); | 2810 var xSquared = squared(x); |
| 2422 return xSquared; | 2811 return xSquared; |
| 2423 }; | 2812 }; |
| 2424 '''); | 2813 '''); |
| 2425 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, | 2814 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2426 matcher: isInferStaticVariableTypesInUnitTask); | 2815 matcher: isInferStaticVariableTypesInUnitTask); |
| 2427 } | 2816 } |
| 2428 | 2817 |
| 2429 void test_perform_recursive() { | 2818 void test_perform_recursive() { |
| 2430 enableStrongMode(); | 2819 enableStrongMode(); |
| 2431 AnalysisTarget firstSource = newSource( | 2820 AnalysisTarget firstSource = newSource( |
| 2432 '/first.dart', | 2821 '/first.dart', |
| 2433 ''' | 2822 ''' |
| 2434 import 'second.dart'; | 2823 import 'second.dart'; |
| 2435 | 2824 |
| 2436 var a = new M(); | 2825 var a = new M(); |
| 2437 var c = b; | 2826 var c = b; |
| 2438 '''); | 2827 '''); |
| 2439 AnalysisTarget secondSource = newSource( | 2828 AnalysisTarget secondSource = newSource( |
| 2440 '/second.dart', | 2829 '/second.dart', |
| 2441 ''' | 2830 ''' |
| 2442 import 'first.dart'; | 2831 import 'first.dart'; |
| 2443 | 2832 |
| 2444 var b = a; | 2833 var b = a; |
| 2445 class M {} | 2834 class M {} |
| 2446 '''); | 2835 '''); |
| 2447 computeResult( | 2836 computeResult( |
| 2448 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT6, | 2837 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, |
| 2449 matcher: isInferStaticVariableTypesInUnitTask); | 2838 matcher: isInferStaticVariableTypesInUnitTask); |
| 2450 CompilationUnit firstUnit = outputs[RESOLVED_UNIT6]; | 2839 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; |
| 2451 computeResult( | 2840 computeResult( |
| 2452 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6); | 2841 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); |
| 2453 CompilationUnit secondUnit = outputs[RESOLVED_UNIT6]; | 2842 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8]; |
| 2454 | 2843 |
| 2455 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2844 VariableDeclaration variableA = |
| 2456 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2845 AstFinder.getTopLevelVariable(firstUnit, 'a'); |
| 2457 VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c'); | 2846 VariableDeclaration variableB = |
| 2458 ClassDeclaration classM = getClass(secondUnit, 'M'); | 2847 AstFinder.getTopLevelVariable(secondUnit, 'b'); |
| 2848 VariableDeclaration variableC = |
| 2849 AstFinder.getTopLevelVariable(firstUnit, 'c'); |
| 2850 ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M'); |
| 2459 DartType typeM = classM.element.type; | 2851 DartType typeM = classM.element.type; |
| 2460 | 2852 |
| 2461 expect(variableA.element.type, typeM); | 2853 expect(variableA.element.type, typeM); |
| 2462 expect(variableB.element.type, typeM); | 2854 expect(variableB.element.type, typeM); |
| 2463 expect(variableB.initializer.staticType, typeM); | 2855 expect(variableB.initializer.staticType, typeM); |
| 2464 expect(variableC.element.type, typeM); | 2856 expect(variableC.element.type, typeM); |
| 2465 expect(variableC.initializer.staticType, typeM); | 2857 expect(variableC.initializer.staticType, typeM); |
| 2466 } | 2858 } |
| 2467 | 2859 |
| 2468 void test_perform_simple() { | 2860 void test_perform_simple() { |
| 2469 enableStrongMode(); | 2861 enableStrongMode(); |
| 2470 AnalysisTarget source = newSource( | 2862 AnalysisTarget source = newSource( |
| 2471 '/test.dart', | 2863 '/test.dart', |
| 2472 ''' | 2864 ''' |
| 2473 var X = 1; | 2865 var X = 1; |
| 2474 | 2866 |
| 2475 var Y = () { | 2867 var Y = () { |
| 2476 return 1 + X; | 2868 return 1 + X; |
| 2477 }; | 2869 }; |
| 2478 '''); | 2870 '''); |
| 2479 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, | 2871 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2480 matcher: isInferStaticVariableTypesInUnitTask); | 2872 matcher: isInferStaticVariableTypesInUnitTask); |
| 2481 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 2873 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2482 TopLevelVariableDeclaration declaration = unit.declarations[1]; | 2874 TopLevelVariableDeclaration declaration = unit.declarations[1]; |
| 2483 FunctionExpression function = | 2875 FunctionExpression function = |
| 2484 declaration.variables.variables[0].initializer; | 2876 declaration.variables.variables[0].initializer; |
| 2485 BlockFunctionBody body = function.body; | 2877 BlockFunctionBody body = function.body; |
| 2486 ReturnStatement statement = body.block.statements[0]; | 2878 ReturnStatement statement = body.block.statements[0]; |
| 2487 Expression expression = statement.expression; | 2879 Expression expression = statement.expression; |
| 2488 InterfaceType intType = context.typeProvider.intType; | 2880 InterfaceType intType = context.typeProvider.intType; |
| 2489 expect(expression.staticType, intType); | 2881 expect(expression.staticType, intType); |
| 2490 } | 2882 } |
| 2883 |
| 2884 test_staticModeHints_forStaticVariableInference() { |
| 2885 context.analysisOptions = |
| 2886 new AnalysisOptionsImpl.from(context.analysisOptions) |
| 2887 ..strongModeHints = true; |
| 2888 Source source = newSource( |
| 2889 '/test.dart', |
| 2890 r''' |
| 2891 var V = [42]; |
| 2892 '''); |
| 2893 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2894 computeResult(target, RESOLVED_UNIT8); |
| 2895 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2896 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2897 // An INFERRED_TYPE_LITERAL error should be generated. |
| 2898 List<AnalysisError> errors = outputs[ |
| 2899 STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] as List<AnalysisError>; |
| 2900 expect(errors, hasLength(1)); |
| 2901 expect(errors[0].errorCode, StrongModeCode.INFERRED_TYPE_LITERAL); |
| 2902 } |
| 2491 } | 2903 } |
| 2492 | 2904 |
| 2493 @reflectiveTest | 2905 @reflectiveTest |
| 2494 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { | 2906 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { |
| 2495 void test_getDeclaration_staticField() { | 2907 void test_getDeclaration_staticField() { |
| 2496 AnalysisTarget source = newSource( | 2908 AnalysisTarget source = newSource( |
| 2497 '/test.dart', | 2909 '/test.dart', |
| 2498 ''' | 2910 ''' |
| 2499 class C { | 2911 class C { |
| 2500 var field = ''; | 2912 var field = ''; |
| 2501 } | 2913 } |
| 2502 '''); | 2914 '''); |
| 2503 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2915 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2504 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2916 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2505 VariableDeclaration declaration = getFieldInClass(unit, 'C', 'field'); | 2917 VariableDeclaration declaration = |
| 2918 AstFinder.getFieldInClass(unit, 'C', 'field'); |
| 2506 VariableElement variable = declaration.name.staticElement; | 2919 VariableElement variable = declaration.name.staticElement; |
| 2507 InferStaticVariableTypeTask inferTask = | 2920 InferStaticVariableTypeTask inferTask = |
| 2508 new InferStaticVariableTypeTask(task.context, variable); | 2921 new InferStaticVariableTypeTask(task.context, variable); |
| 2509 expect(inferTask.getDeclaration(unit), declaration); | 2922 expect(inferTask.getDeclaration(unit), declaration); |
| 2510 } | 2923 } |
| 2511 | 2924 |
| 2512 void test_getDeclaration_topLevel() { | 2925 void test_getDeclaration_topLevel() { |
| 2513 AnalysisTarget source = newSource( | 2926 AnalysisTarget source = newSource( |
| 2514 '/test.dart', | 2927 '/test.dart', |
| 2515 ''' | 2928 ''' |
| 2516 var topLevel = ''; | 2929 var topLevel = ''; |
| 2517 '''); | 2930 '''); |
| 2518 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2931 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2519 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2932 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2520 VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel'); | 2933 VariableDeclaration declaration = |
| 2934 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2521 VariableElement variable = declaration.name.staticElement; | 2935 VariableElement variable = declaration.name.staticElement; |
| 2522 InferStaticVariableTypeTask inferTask = | 2936 InferStaticVariableTypeTask inferTask = |
| 2523 new InferStaticVariableTypeTask(task.context, variable); | 2937 new InferStaticVariableTypeTask(task.context, variable); |
| 2524 expect(inferTask.getDeclaration(unit), declaration); | 2938 expect(inferTask.getDeclaration(unit), declaration); |
| 2525 } | 2939 } |
| 2526 | 2940 |
| 2527 void test_perform() { | 2941 void test_perform() { |
| 2528 enableStrongMode(); | 2942 enableStrongMode(); |
| 2529 AnalysisTarget source = newSource( | 2943 AnalysisTarget source = newSource( |
| 2530 '/test3.dart', | 2944 '/test3.dart', |
| 2531 ''' | 2945 ''' |
| 2532 var topLevel3 = ''; | 2946 var topLevel3 = ''; |
| 2533 class C { | 2947 class C { |
| 2534 var field3 = topLevel3; | 2948 var field3 = topLevel3; |
| 2535 } | 2949 } |
| 2536 '''); | 2950 '''); |
| 2537 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2951 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2538 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2952 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2539 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3'); | 2953 VariableDeclaration topLevelDecl = |
| 2540 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); | 2954 AstFinder.getTopLevelVariable(unit, 'topLevel3'); |
| 2955 VariableDeclaration fieldDecl = |
| 2956 AstFinder.getFieldInClass(unit, 'C', 'field3'); |
| 2541 VariableElement topLevel = topLevelDecl.name.staticElement; | 2957 VariableElement topLevel = topLevelDecl.name.staticElement; |
| 2542 VariableElement field = fieldDecl.name.staticElement; | 2958 VariableElement field = fieldDecl.name.staticElement; |
| 2543 | 2959 |
| 2544 computeResult(field, INFERRED_STATIC_VARIABLE, | 2960 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 2545 matcher: isInferStaticVariableTypeTask); | 2961 matcher: isInferStaticVariableTypeTask); |
| 2546 InterfaceType stringType = context.typeProvider.stringType; | 2962 InterfaceType stringType = context.typeProvider.stringType; |
| 2547 expect(topLevel.type, stringType); | 2963 expect(topLevel.type, stringType); |
| 2548 expect(field.type, stringType); | 2964 expect(field.type, stringType); |
| 2549 expect(fieldDecl.initializer.staticType, stringType); | 2965 expect(fieldDecl.initializer.staticType, stringType); |
| 2550 } | 2966 } |
| 2551 | 2967 |
| 2552 void test_perform_const() { | 2968 void test_perform_const() { |
| 2553 enableStrongMode(); | 2969 enableStrongMode(); |
| 2554 AnalysisTarget source = newSource( | 2970 AnalysisTarget source = newSource( |
| 2555 '/test.dart', | 2971 '/test.dart', |
| 2556 ''' | 2972 ''' |
| 2557 const topLevel = "hello"; | 2973 const topLevel = "hello"; |
| 2558 class C { | 2974 class C { |
| 2559 var field = topLevel; | 2975 var field = topLevel; |
| 2560 } | 2976 } |
| 2561 '''); | 2977 '''); |
| 2562 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2978 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2563 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2979 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2564 VariableElement topLevel = | 2980 VariableElement topLevel = |
| 2565 getTopLevelVariable(unit, 'topLevel').name.staticElement; | 2981 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement; |
| 2566 VariableElement field = | 2982 VariableElement field = |
| 2567 getFieldInClass(unit, 'C', 'field').name.staticElement; | 2983 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement; |
| 2568 | 2984 |
| 2569 computeResult(field, INFERRED_STATIC_VARIABLE, | 2985 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 2570 matcher: isInferStaticVariableTypeTask); | 2986 matcher: isInferStaticVariableTypeTask); |
| 2571 InterfaceType stringType = context.typeProvider.stringType; | 2987 InterfaceType stringType = context.typeProvider.stringType; |
| 2572 expect(topLevel.type, stringType); | 2988 expect(topLevel.type, stringType); |
| 2573 expect(field.type, stringType); | 2989 expect(field.type, stringType); |
| 2574 } | 2990 } |
| 2575 | 2991 |
| 2576 void test_perform_cycle() { | 2992 void test_perform_cycle() { |
| 2577 enableStrongMode(); | 2993 enableStrongMode(); |
| 2578 AnalysisTarget source = newSource( | 2994 AnalysisTarget source = newSource( |
| 2579 '/test.dart', | 2995 '/test.dart', |
| 2580 ''' | 2996 ''' |
| 2581 var piFirst = true; | 2997 var piFirst = true; |
| 2582 var pi = piFirst ? 3.14 : tau / 2; | 2998 var pi = piFirst ? 3.14 : tau / 2; |
| 2583 var tau = piFirst ? pi * 2 : 6.28; | 2999 var tau = piFirst ? pi * 2 : 6.28; |
| 2584 '''); | 3000 '''); |
| 2585 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3001 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2586 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3002 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2587 VariableElement piFirst = | 3003 VariableElement piFirst = |
| 2588 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 3004 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 2589 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 3005 VariableElement pi = |
| 2590 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 3006 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 3007 VariableElement tau = |
| 3008 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 2591 | 3009 |
| 2592 computeResult(piFirst, INFERRED_STATIC_VARIABLE, | 3010 computeResult(piFirst, INFERRED_STATIC_VARIABLE, |
| 2593 matcher: isInferStaticVariableTypeTask); | 3011 matcher: isInferStaticVariableTypeTask); |
| 2594 expect(piFirst.type, context.typeProvider.boolType); | 3012 expect(piFirst.type, context.typeProvider.boolType); |
| 2595 expect(pi.type.isDynamic, isTrue); | 3013 expect(pi.type.isDynamic, isTrue); |
| 2596 expect(tau.type.isDynamic, isTrue); | 3014 expect(tau.type.isDynamic, isTrue); |
| 2597 } | 3015 } |
| 2598 | 3016 |
| 2599 void test_perform_error() { | 3017 void test_perform_error() { |
| 2600 enableStrongMode(); | 3018 enableStrongMode(); |
| 2601 AnalysisTarget source = newSource( | 3019 AnalysisTarget source = newSource( |
| 2602 '/test.dart', | 3020 '/test.dart', |
| 2603 ''' | 3021 ''' |
| 2604 var a = '' / null; | 3022 var a = '' / null; |
| 2605 '''); | 3023 '''); |
| 2606 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3024 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2607 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3025 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2608 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 3026 VariableElement a = |
| 3027 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 2609 | 3028 |
| 2610 computeResult(a, INFERRED_STATIC_VARIABLE, | 3029 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 2611 matcher: isInferStaticVariableTypeTask); | 3030 matcher: isInferStaticVariableTypeTask); |
| 2612 expect(a.type.isDynamic, isTrue); | 3031 expect(a.type.isDynamic, isTrue); |
| 2613 } | 3032 } |
| 2614 | 3033 |
| 2615 void test_perform_null() { | 3034 void test_perform_null() { |
| 2616 enableStrongMode(); | 3035 enableStrongMode(); |
| 2617 AnalysisTarget source = newSource( | 3036 AnalysisTarget source = newSource( |
| 2618 '/test.dart', | 3037 '/test.dart', |
| 2619 ''' | 3038 ''' |
| 2620 var a = null; | 3039 var a = null; |
| 2621 '''); | 3040 '''); |
| 2622 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 3041 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2623 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3042 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2624 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 3043 VariableElement a = |
| 3044 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 2625 | 3045 |
| 2626 computeResult(a, INFERRED_STATIC_VARIABLE, | 3046 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 2627 matcher: isInferStaticVariableTypeTask); | 3047 matcher: isInferStaticVariableTypeTask); |
| 2628 expect(a.type.isDynamic, isTrue); | 3048 expect(a.type.isDynamic, isTrue); |
| 2629 } | 3049 } |
| 2630 } | 3050 } |
| 2631 | 3051 |
| 2632 @reflectiveTest | 3052 @reflectiveTest |
| 2633 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { | 3053 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { |
| 2634 test_perform() { | 3054 test_perform() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2658 bool ready = outputs[LIBRARY_ERRORS_READY]; | 3078 bool ready = outputs[LIBRARY_ERRORS_READY]; |
| 2659 expect(ready, isTrue); | 3079 expect(ready, isTrue); |
| 2660 expect(context.getErrors(library).errors, hasLength(1)); | 3080 expect(context.getErrors(library).errors, hasLength(1)); |
| 2661 expect(context.getErrors(part1).errors, hasLength(1)); | 3081 expect(context.getErrors(part1).errors, hasLength(1)); |
| 2662 expect(context.getErrors(part2).errors, hasLength(1)); | 3082 expect(context.getErrors(part2).errors, hasLength(1)); |
| 2663 } | 3083 } |
| 2664 } | 3084 } |
| 2665 | 3085 |
| 2666 @reflectiveTest | 3086 @reflectiveTest |
| 2667 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { | 3087 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { |
| 3088 List<AnalysisError> getLibraryUnitErrors( |
| 3089 Map<ResultDescriptor, dynamic> outputs) { |
| 3090 return outputs[LIBRARY_UNIT_ERRORS] as List<AnalysisError>; |
| 3091 } |
| 3092 |
| 2668 test_perform_definingCompilationUnit() { | 3093 test_perform_definingCompilationUnit() { |
| 2669 AnalysisTarget library = | 3094 AnalysisTarget library = |
| 2670 newSource('/test.dart', 'library test; import "dart:math";'); | 3095 newSource('/test.dart', 'library test; import "dart:math";'); |
| 2671 computeResult( | 3096 computeResult( |
| 2672 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS, | 3097 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS, |
| 2673 matcher: isLibraryUnitErrorsTask); | 3098 matcher: isLibraryUnitErrorsTask); |
| 2674 expect(outputs, hasLength(1)); | 3099 expect(outputs, hasLength(1)); |
| 2675 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; | 3100 List<AnalysisError> errors = getLibraryUnitErrors(outputs); |
| 2676 expect(errors, hasLength(1)); | 3101 expect(errors, hasLength(1)); |
| 2677 } | 3102 } |
| 2678 | 3103 |
| 2679 test_perform_partInSingleLibrary() { | 3104 test_perform_partInSingleLibrary() { |
| 2680 AnalysisTarget library = | 3105 AnalysisTarget library = |
| 2681 newSource('/lib.dart', 'library test; part "part.dart";'); | 3106 newSource('/lib.dart', 'library test; part "part.dart";'); |
| 2682 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 3107 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 2683 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS, | 3108 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS, |
| 2684 matcher: isLibraryUnitErrorsTask); | 3109 matcher: isLibraryUnitErrorsTask); |
| 2685 expect(outputs, hasLength(1)); | 3110 expect(outputs, hasLength(1)); |
| 2686 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; | 3111 List<AnalysisError> errors = getLibraryUnitErrors(outputs); |
| 2687 expect(errors, hasLength(0)); | 3112 expect(errors, hasLength(0)); |
| 2688 } | 3113 } |
| 2689 } | 3114 } |
| 2690 | 3115 |
| 2691 @reflectiveTest | 3116 @reflectiveTest |
| 2692 class ParseDartTaskTest extends _AbstractDartTaskTest { | 3117 class ParseDartTaskTest extends _AbstractDartTaskTest { |
| 2693 Source source; | 3118 Source source; |
| 2694 | 3119 |
| 2695 test_perform() { | 3120 test_perform() { |
| 2696 _performParseTask(r''' | 3121 _performParseTask(r''' |
| 2697 part of lib; | 3122 part of lib; |
| 2698 class B {}'''); | 3123 class B {}'''); |
| 2699 expect(outputs, hasLength(8)); | 3124 expect(outputs, hasLength(11)); |
| 2700 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 3125 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2701 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 3126 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2702 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 3127 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2703 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 3128 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 3129 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 2704 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3130 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2705 expect(outputs[PARSED_UNIT], isNotNull); | 3131 expect(outputs[PARSED_UNIT], isNotNull); |
| 3132 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3133 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 2706 expect(outputs[SOURCE_KIND], SourceKind.PART); | 3134 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2707 expect(outputs[UNITS], hasLength(1)); | 3135 expect(outputs[UNITS], hasLength(1)); |
| 2708 } | 3136 } |
| 2709 | 3137 |
| 2710 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { | 3138 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { |
| 2711 // Parse "lib.dart" to let the context know that "test.dart" is included. | 3139 // Parse "lib.dart" to let the context know that "test.dart" is included. |
| 2712 computeResult( | 3140 computeResult( |
| 2713 newSource( | 3141 newSource( |
| 2714 '/lib.dart', | 3142 '/lib.dart', |
| 2715 r''' | 3143 r''' |
| 2716 library lib; | 3144 library lib; |
| 2717 part 'test.dart'; | 3145 part 'test.dart'; |
| 2718 '''), | 3146 '''), |
| 2719 PARSED_UNIT); | 3147 PARSED_UNIT); |
| 2720 // If there are no the "part of" directive, then it is not a part. | 3148 // If there are no the "part of" directive, then it is not a part. |
| 2721 _performParseTask(''); | 3149 _performParseTask(''); |
| 2722 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3150 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2723 } | 3151 } |
| 2724 | 3152 |
| 2725 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { | 3153 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { |
| 2726 _performParseTask(''); | 3154 _performParseTask(''); |
| 2727 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3155 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2728 } | 3156 } |
| 2729 | 3157 |
| 2730 test_perform_doesNotExist() { | 3158 test_perform_doesNotExist() { |
| 2731 _performParseTask(null); | 3159 _performParseTask(null); |
| 2732 expect(outputs, hasLength(8)); | 3160 expect(outputs, hasLength(11)); |
| 2733 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 3161 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2734 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 3162 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2735 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 3163 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2736 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 3164 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 3165 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 2737 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3166 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2738 expect(outputs[PARSED_UNIT], isNotNull); | 3167 expect(outputs[PARSED_UNIT], isNotNull); |
| 2739 expect(outputs[SOURCE_KIND], SourceKind.UNKNOWN); | 3168 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3169 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 3170 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2740 expect(outputs[UNITS], hasLength(1)); | 3171 expect(outputs[UNITS], hasLength(1)); |
| 2741 } | 3172 } |
| 2742 | 3173 |
| 3174 test_perform_flushTokenStream() { |
| 3175 _performParseTask(r''' |
| 3176 class Test {} |
| 3177 '''); |
| 3178 expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED); |
| 3179 } |
| 3180 |
| 2743 test_perform_invalidDirectives() { | 3181 test_perform_invalidDirectives() { |
| 2744 _performParseTask(r''' | 3182 _performParseTask(r''' |
| 2745 library lib; | 3183 library lib; |
| 2746 import '/does/not/exist.dart'; | 3184 import '/does/not/exist.dart'; |
| 2747 import '://invaliduri.dart'; | 3185 import '://invaliduri.dart'; |
| 2748 export '${a}lib3.dart'; | 3186 export '${a}lib3.dart'; |
| 2749 part 'part.dart'; | 3187 part 'part.dart'; |
| 2750 class A {}'''); | 3188 class A {}'''); |
| 2751 expect(outputs, hasLength(8)); | 3189 expect(outputs, hasLength(11)); |
| 2752 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | 3190 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 2753 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 3191 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2754 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 3192 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 2755 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 3193 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 3194 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); |
| 2756 expect(outputs[PARSE_ERRORS], hasLength(2)); | 3195 expect(outputs[PARSE_ERRORS], hasLength(2)); |
| 2757 expect(outputs[PARSED_UNIT], isNotNull); | 3196 expect(outputs[PARSED_UNIT], isNotNull); |
| 3197 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3198 expect(outputs[REFERENCED_SOURCES], hasLength(4)); |
| 2758 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3199 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2759 expect(outputs[UNITS], hasLength(2)); | 3200 expect(outputs[UNITS], hasLength(2)); |
| 2760 } | 3201 } |
| 2761 | 3202 |
| 2762 test_perform_library() { | 3203 test_perform_library() { |
| 2763 _performParseTask(r''' | 3204 _performParseTask(r''' |
| 2764 library lib; | 3205 library lib; |
| 2765 import 'lib2.dart'; | 3206 import 'lib2.dart'; |
| 2766 export 'lib3.dart'; | 3207 export 'lib3.dart'; |
| 2767 part 'part.dart'; | 3208 part 'part.dart'; |
| 2768 class A {'''); | 3209 class A {'''); |
| 2769 expect(outputs, hasLength(8)); | 3210 expect(outputs, hasLength(11)); |
| 2770 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | 3211 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 2771 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 3212 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 2772 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 3213 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 2773 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 3214 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 3215 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); |
| 2774 expect(outputs[PARSE_ERRORS], hasLength(1)); | 3216 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 2775 expect(outputs[PARSED_UNIT], isNotNull); | 3217 expect(outputs[PARSED_UNIT], isNotNull); |
| 3218 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3219 expect(outputs[REFERENCED_SOURCES], hasLength(5)); |
| 2776 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3220 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2777 expect(outputs[UNITS], hasLength(2)); | 3221 expect(outputs[UNITS], hasLength(2)); |
| 2778 } | 3222 } |
| 2779 | 3223 |
| 3224 test_perform_library_configurations_bool1() { |
| 3225 context.declaredVariables.define('dart.library.io', 'true'); |
| 3226 newSource('/foo.dart', ''); |
| 3227 newSource('/foo_io.dart', ''); |
| 3228 newSource('/foo_html.dart', ''); |
| 3229 newSource('/bar.dart', ''); |
| 3230 newSource('/bar_io.dart', ''); |
| 3231 newSource('/bar_html.dart', ''); |
| 3232 _performParseTask(r''' |
| 3233 import 'foo.dart' |
| 3234 if (dart.library.io) 'foo_io.dart' |
| 3235 if (dart.library.html) 'foo_html.dart'; |
| 3236 export 'bar.dart' |
| 3237 if (dart.library.io) 'bar_io.dart' |
| 3238 if (dart.library.html) 'bar_html.dart'; |
| 3239 '''); |
| 3240 var unit = outputs[PARSED_UNIT] as CompilationUnit; |
| 3241 |
| 3242 var imported = outputs[IMPORTED_LIBRARIES] as List<Source>; |
| 3243 _assertContainsOnlyShortName(imported, 'foo_io.dart'); |
| 3244 |
| 3245 var import = unit.directives[0] as ImportDirective; |
| 3246 expect(import.uriSource.shortName, 'foo.dart'); |
| 3247 expect(import.selectedSource.shortName, 'foo_io.dart'); |
| 3248 expect(import.configurations[0].uriSource.shortName, 'foo_io.dart'); |
| 3249 expect(import.configurations[1].uriSource.shortName, 'foo_html.dart'); |
| 3250 |
| 3251 var exported = outputs[EXPORTED_LIBRARIES] as List<Source>; |
| 3252 _assertContainsOnlyShortName(exported, 'bar_io.dart'); |
| 3253 |
| 3254 var export = unit.directives[1] as ExportDirective; |
| 3255 expect(export.uriSource.shortName, 'bar.dart'); |
| 3256 expect(export.selectedSource.shortName, 'bar_io.dart'); |
| 3257 expect(export.configurations[0].uriSource.shortName, 'bar_io.dart'); |
| 3258 expect(export.configurations[1].uriSource.shortName, 'bar_html.dart'); |
| 3259 |
| 3260 var refSources = outputs[REFERENCED_SOURCES] as List<Source>; |
| 3261 var refNames = refSources.map((source) => source.shortName).toList(); |
| 3262 expect(refNames, contains('test.dart')); |
| 3263 expect(refNames, contains('foo.dart')); |
| 3264 expect(refNames, contains('foo_io.dart')); |
| 3265 expect(refNames, contains('foo_html.dart')); |
| 3266 expect(refNames, contains('bar.dart')); |
| 3267 expect(refNames, contains('bar_io.dart')); |
| 3268 expect(refNames, contains('bar_html.dart')); |
| 3269 } |
| 3270 |
| 3271 test_perform_library_configurations_bool2() { |
| 3272 context.declaredVariables.define('dart.library.html', 'true'); |
| 3273 newSource('/foo.dart', ''); |
| 3274 newSource('/foo_io.dart', ''); |
| 3275 newSource('/foo_html.dart', ''); |
| 3276 _performParseTask(r''' |
| 3277 import 'foo.dart' |
| 3278 if (dart.library.io) 'foo_io.dart' |
| 3279 if (dart.library.html) 'foo_html.dart'; |
| 3280 '''); |
| 3281 var imported = outputs[IMPORTED_LIBRARIES] as List<Source>; |
| 3282 _assertContainsOnlyShortName(imported, 'foo_html.dart'); |
| 3283 } |
| 3284 |
| 3285 test_perform_library_configurations_default() { |
| 3286 context.declaredVariables.define('dart.library.io', 'false'); |
| 3287 newSource('/foo.dart', ''); |
| 3288 newSource('/foo_io.dart', ''); |
| 3289 newSource('/foo_html.dart', ''); |
| 3290 _performParseTask(r''' |
| 3291 import 'foo.dart' |
| 3292 if (dart.library.io) 'foo_io.dart' |
| 3293 if (dart.library.html) 'foo_html.dart'; |
| 3294 '''); |
| 3295 var imported = outputs[IMPORTED_LIBRARIES] as List<Source>; |
| 3296 _assertContainsOnlyShortName(imported, 'foo.dart'); |
| 3297 } |
| 3298 |
| 3299 test_perform_library_configurations_preferFirst() { |
| 3300 context.declaredVariables.define('dart.library.io', 'true'); |
| 3301 context.declaredVariables.define('dart.library.html', 'true'); |
| 3302 newSource('/foo.dart', ''); |
| 3303 newSource('/foo_io.dart', ''); |
| 3304 newSource('/foo_html.dart', ''); |
| 3305 _performParseTask(r''' |
| 3306 import 'foo.dart' |
| 3307 if (dart.library.io) 'foo_io.dart' |
| 3308 if (dart.library.html) 'foo_html.dart'; |
| 3309 '''); |
| 3310 |
| 3311 var imported = outputs[IMPORTED_LIBRARIES] as List<Source>; |
| 3312 _assertContainsOnlyShortName(imported, 'foo_io.dart'); |
| 3313 |
| 3314 var unit = outputs[PARSED_UNIT] as CompilationUnit; |
| 3315 var import = unit.directives[0] as ImportDirective; |
| 3316 expect(import.uriSource.shortName, 'foo.dart'); |
| 3317 expect(import.selectedSource.shortName, 'foo_io.dart'); |
| 3318 expect(import.configurations[0].uriSource.shortName, 'foo_io.dart'); |
| 3319 expect(import.configurations[1].uriSource.shortName, 'foo_html.dart'); |
| 3320 } |
| 3321 |
| 3322 test_perform_library_configurations_value() { |
| 3323 context.declaredVariables.define('dart.platform', 'Windows'); |
| 3324 newSource('/foo.dart', ''); |
| 3325 newSource('/foo_posix.dart', ''); |
| 3326 newSource('/foo_windows.dart', ''); |
| 3327 _performParseTask(r''' |
| 3328 import 'foo.dart' |
| 3329 if (dart.platform == 'Posix') 'foo_posix.dart' |
| 3330 if (dart.platform == 'Windows') 'foo_windows.dart'; |
| 3331 '''); |
| 3332 var imported = outputs[IMPORTED_LIBRARIES] as List<Source>; |
| 3333 _assertContainsOnlyShortName(imported, 'foo_windows.dart'); |
| 3334 } |
| 3335 |
| 2780 test_perform_library_selfReferenceAsPart() { | 3336 test_perform_library_selfReferenceAsPart() { |
| 2781 _performParseTask(r''' | 3337 _performParseTask(r''' |
| 2782 library lib; | 3338 library lib; |
| 2783 part 'test.dart'; | 3339 part 'test.dart'; |
| 2784 '''); | 3340 '''); |
| 2785 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source])); | 3341 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source])); |
| 2786 } | 3342 } |
| 2787 | 3343 |
| 2788 test_perform_part() { | 3344 test_perform_part() { |
| 2789 _performParseTask(r''' | 3345 _performParseTask(r''' |
| 2790 part of lib; | 3346 part of lib; |
| 2791 class B {}'''); | 3347 class B {}'''); |
| 2792 expect(outputs, hasLength(8)); | 3348 expect(outputs, hasLength(11)); |
| 2793 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 3349 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2794 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 3350 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2795 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 3351 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2796 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 3352 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 3353 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 2797 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3354 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2798 expect(outputs[PARSED_UNIT], isNotNull); | 3355 expect(outputs[PARSED_UNIT], isNotNull); |
| 3356 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3357 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 2799 expect(outputs[SOURCE_KIND], SourceKind.PART); | 3358 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2800 expect(outputs[UNITS], hasLength(1)); | 3359 expect(outputs[UNITS], hasLength(1)); |
| 2801 } | 3360 } |
| 2802 | 3361 |
| 3362 /** |
| 3363 * Assert that [sources] contains either just a source with the given |
| 3364 * [expectedShortName], or it and the `dart:core` source. |
| 3365 */ |
| 3366 void _assertContainsOnlyShortName( |
| 3367 List<Source> sources, String expectedShortName) { |
| 3368 Iterable<String> shortNames = sources.map((s) => s.shortName); |
| 3369 if (shortNames.length == 2) { |
| 3370 expect(shortNames, unorderedEquals(['core.dart', expectedShortName])); |
| 3371 } else { |
| 3372 expect(shortNames, unorderedEquals([expectedShortName])); |
| 3373 } |
| 3374 } |
| 3375 |
| 2803 void _performParseTask(String content) { | 3376 void _performParseTask(String content) { |
| 2804 source = newSource('/test.dart', content); | 3377 if (content == null) { |
| 3378 source = resourceProvider.getFile('/test.dart').createSource(); |
| 3379 } else { |
| 3380 source = newSource('/test.dart', content); |
| 3381 } |
| 2805 computeResult(source, PARSED_UNIT, matcher: isParseDartTask); | 3382 computeResult(source, PARSED_UNIT, matcher: isParseDartTask); |
| 2806 } | 3383 } |
| 2807 | 3384 |
| 2808 static void _assertHasCore(List<Source> sources, int lenght) { | 3385 static void _assertHasCore(dynamic sourceList, int lenght) { |
| 3386 List<Source> sources = sourceList as List<Source>; |
| 2809 expect(sources, hasLength(lenght)); | 3387 expect(sources, hasLength(lenght)); |
| 2810 expect(sources, contains(predicate((Source s) { | 3388 expect(sources, contains(predicate((Source s) { |
| 2811 return s.fullName.endsWith('core.dart'); | 3389 return s.fullName.endsWith('core.dart'); |
| 2812 }))); | 3390 }))); |
| 2813 } | 3391 } |
| 2814 } | 3392 } |
| 2815 | 3393 |
| 2816 @reflectiveTest | 3394 @reflectiveTest |
| 2817 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { | 3395 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { |
| 2818 test_perform() { | 3396 test_perform_strong_importExport() { |
| 2819 enableStrongMode(); | |
| 2820 Source source = newSource( | |
| 2821 '/test.dart', | |
| 2822 ''' | |
| 2823 int a = b; | |
| 2824 int b = c; | |
| 2825 var d = 0; | |
| 2826 class A {} | |
| 2827 class C { | |
| 2828 static final f = ''; | |
| 2829 var g = 0; | |
| 2830 } | |
| 2831 '''); | |
| 2832 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | |
| 2833 computeResult(target, RESOLVED_UNIT5, | |
| 2834 matcher: isPartiallyResolveUnitReferencesTask); | |
| 2835 // Test the outputs | |
| 2836 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(4)); | |
| 2837 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | |
| 2838 expect(unit, same(outputs[RESOLVED_UNIT5])); | |
| 2839 // Test the state of the AST | |
| 2840 TopLevelVariableDeclaration a = unit.declarations[0]; | |
| 2841 VariableDeclaration variableA = a.variables.variables[0]; | |
| 2842 SimpleIdentifier initializer = variableA.initializer; | |
| 2843 expect(initializer.staticElement, isNotNull); | |
| 2844 } | |
| 2845 | |
| 2846 test_perform_importExport() { | |
| 2847 newSource( | 3397 newSource( |
| 2848 '/a.dart', | 3398 '/a.dart', |
| 2849 ''' | 3399 ''' |
| 2850 library a; | 3400 library a; |
| 2851 class A<T> { | 3401 class A<T> { |
| 2852 T m() {} | 3402 T m() {} |
| 2853 } | 3403 } |
| 2854 '''); | 3404 '''); |
| 2855 newSource( | 3405 newSource( |
| 2856 '/b.dart', | 3406 '/b.dart', |
| 2857 ''' | 3407 ''' |
| 2858 library b; | 3408 library b; |
| 2859 export 'a.dart'; | 3409 export 'a.dart'; |
| 2860 '''); | 3410 '''); |
| 2861 Source sourceC = newSource( | 3411 Source sourceC = newSource( |
| 2862 '/c.dart', | 3412 '/c.dart', |
| 2863 ''' | 3413 ''' |
| 2864 library c; | 3414 library c; |
| 2865 import 'b.dart'; | 3415 import 'b.dart'; |
| 2866 main() { | 3416 main() { |
| 2867 new A<int>().m(); | 3417 new A<int>().m(); |
| 2868 } | 3418 } |
| 2869 '''); | 3419 '''); |
| 2870 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5, | 3420 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT7, |
| 2871 matcher: isPartiallyResolveUnitReferencesTask); | 3421 matcher: isPartiallyResolveUnitReferencesTask); |
| 2872 // validate | 3422 // validate |
| 2873 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); | 3423 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); |
| 2874 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3424 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2875 expect(unit, isNotNull); | 3425 expect(unit, isNotNull); |
| 2876 | 3426 |
| 2877 FunctionDeclaration mainFunction = unit.declarations[0]; | 3427 FunctionDeclaration mainFunction = unit.declarations[0]; |
| 2878 expect(mainFunction.element, isNotNull); | 3428 expect(mainFunction.element, isNotNull); |
| 2879 BlockFunctionBody body = mainFunction.functionExpression.body; | 3429 BlockFunctionBody body = mainFunction.functionExpression.body; |
| 2880 List<Statement> statements = body.block.statements; | 3430 List<Statement> statements = body.block.statements; |
| 2881 ExpressionStatement statement = statements[0]; | 3431 ExpressionStatement statement = statements[0]; |
| 2882 MethodInvocation invocation = statement.expression; | 3432 MethodInvocation invocation = statement.expression; |
| 2883 MethodElement methodElement = invocation.methodName.staticElement; | 3433 MethodElement methodElement = invocation.methodName.staticElement; |
| 2884 expect(methodElement, isNull); | 3434 expect(methodElement, isNull); |
| 2885 } | 3435 } |
| 2886 | 3436 |
| 2887 test_perform_notResolved() { | 3437 test_perform_strong_inferable() { |
| 2888 enableStrongMode(); | 3438 enableStrongMode(); |
| 2889 Source source = newSource( | 3439 Source source = newSource( |
| 2890 '/test.dart', | 3440 '/test.dart', |
| 3441 ''' |
| 3442 int a = b; |
| 3443 int b = c; |
| 3444 var d = 0; |
| 3445 class A {} |
| 3446 class C { |
| 3447 static final f = ''; |
| 3448 var g = 0; |
| 3449 } |
| 3450 '''); |
| 3451 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3452 computeResult(target, RESOLVED_UNIT7, |
| 3453 matcher: isPartiallyResolveUnitReferencesTask); |
| 3454 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3455 // INFERABLE_STATIC_VARIABLES_IN_UNIT |
| 3456 { |
| 3457 List<VariableElement> variables = |
| 3458 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] as List<VariableElement>; |
| 3459 expect(variables, hasLength(4)); |
| 3460 expect(variables.map((v) => v.displayName), |
| 3461 unorderedEquals(['a', 'b', 'd', 'f'])); |
| 3462 } |
| 3463 // Test the state of the AST |
| 3464 TopLevelVariableDeclaration a = unit.declarations[0]; |
| 3465 VariableDeclaration variableA = a.variables.variables[0]; |
| 3466 SimpleIdentifier initializer = variableA.initializer; |
| 3467 expect(initializer.staticElement, isNotNull); |
| 3468 } |
| 3469 |
| 3470 test_perform_strong_notResolved() { |
| 3471 enableStrongMode(); |
| 3472 Source source = newSource( |
| 3473 '/test.dart', |
| 2891 ''' | 3474 ''' |
| 2892 int A; | 3475 int A; |
| 2893 f1() { | 3476 f1() { |
| 2894 A; | 3477 A; |
| 2895 } | 3478 } |
| 2896 var f2 = () { | 3479 var f2 = () { |
| 2897 A; | 3480 A; |
| 2898 void f3() { | 3481 void f3() { |
| 2899 A; | 3482 A; |
| 2900 } | 3483 } |
| 2901 } | 3484 } |
| 2902 class C { | 3485 class C { |
| 2903 C() { | 3486 C() { |
| 2904 A; | 3487 A; |
| 2905 } | 3488 } |
| 2906 m() { | 3489 m() { |
| 2907 A; | 3490 A; |
| 2908 } | 3491 } |
| 2909 } | 3492 } |
| 2910 '''); | 3493 '''); |
| 2911 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3494 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2912 computeResult(target, RESOLVED_UNIT5, | 3495 computeResult(target, RESOLVED_UNIT7, |
| 2913 matcher: isPartiallyResolveUnitReferencesTask); | 3496 matcher: isPartiallyResolveUnitReferencesTask); |
| 2914 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3497 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2915 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3498 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 2916 | 3499 |
| 2917 void expectReference(BlockFunctionBody body, bool isResolved) { | 3500 void expectReference(BlockFunctionBody body, bool isResolved) { |
| 2918 ExpressionStatement statement = body.block.statements[0]; | 3501 ExpressionStatement statement = body.block.statements[0]; |
| 2919 SimpleIdentifier reference = statement.expression; | 3502 SimpleIdentifier reference = statement.expression; |
| 2920 expect(reference.staticElement, isResolved ? isNotNull : isNull); | 3503 expect(reference.staticElement, isResolved ? isNotNull : isNull); |
| 2921 } | 3504 } |
| 3505 |
| 2922 // | 3506 // |
| 2923 // The reference to 'A' in 'f1' should not be resolved. | 3507 // The reference to 'A' in 'f1' should not be resolved. |
| 2924 // | 3508 // |
| 2925 FunctionDeclaration f1 = declarations[1]; | 3509 FunctionDeclaration f1 = declarations[1]; |
| 2926 expectReference(f1.functionExpression.body, false); | 3510 expectReference(f1.functionExpression.body, false); |
| 2927 // | 3511 // |
| 2928 // The references to 'A' in 'f2' should be resolved. | 3512 // The references to 'A' in 'f2' should be resolved. |
| 2929 // | 3513 // |
| 2930 TopLevelVariableDeclaration f2 = declarations[2]; | 3514 TopLevelVariableDeclaration f2 = declarations[2]; |
| 2931 FunctionExpression expression2 = f2.variables.variables[0].initializer; | 3515 FunctionExpression expression2 = f2.variables.variables[0].initializer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2944 | 3528 |
| 2945 ConstructorDeclaration constructor = members[0]; | 3529 ConstructorDeclaration constructor = members[0]; |
| 2946 expectReference(constructor.body, false); | 3530 expectReference(constructor.body, false); |
| 2947 | 3531 |
| 2948 MethodDeclaration method = members[1]; | 3532 MethodDeclaration method = members[1]; |
| 2949 expectReference(method.body, false); | 3533 expectReference(method.body, false); |
| 2950 } | 3534 } |
| 2951 } | 3535 } |
| 2952 | 3536 |
| 2953 @reflectiveTest | 3537 @reflectiveTest |
| 3538 class ReferencedNamesBuilderTest extends _AbstractDartTaskTest { |
| 3539 void setUp() { |
| 3540 super.setUp(); |
| 3541 context.analysisOptions = new AnalysisOptionsImpl() |
| 3542 ..enableGenericMethods = true |
| 3543 ..strongMode = true; |
| 3544 } |
| 3545 |
| 3546 test_class_constructor() { |
| 3547 ReferencedNames info = _computeReferencedNames(''' |
| 3548 class U { |
| 3549 U.named(A a, B b) { |
| 3550 C c = null; |
| 3551 } |
| 3552 } |
| 3553 '''); |
| 3554 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3555 expect(info.superToSubs.keys, isEmpty); |
| 3556 expect(info.instantiatedNames, isEmpty); |
| 3557 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3558 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B'])); |
| 3559 } |
| 3560 |
| 3561 test_class_extendedUsedUnnamedConstructorNames() { |
| 3562 ReferencedNames info = _computeReferencedNames(''' |
| 3563 class U1 extends A { |
| 3564 U1() : super(); |
| 3565 } |
| 3566 class U2 extends p.B { |
| 3567 U2() : super(); |
| 3568 } |
| 3569 class U3 extends p.C { |
| 3570 U3() : super.named(); |
| 3571 } |
| 3572 '''); |
| 3573 expect( |
| 3574 info.extendedUsedUnnamedConstructorNames, unorderedEquals(['A', 'B'])); |
| 3575 } |
| 3576 |
| 3577 test_class_field() { |
| 3578 ReferencedNames info = _computeReferencedNames(''' |
| 3579 class U { |
| 3580 A f = new B(); |
| 3581 } |
| 3582 '''); |
| 3583 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3584 expect(info.superToSubs.keys, isEmpty); |
| 3585 expect(info.instantiatedNames, unorderedEquals(['B'])); |
| 3586 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3587 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B'])); |
| 3588 } |
| 3589 |
| 3590 test_class_getter() { |
| 3591 ReferencedNames info = _computeReferencedNames(''' |
| 3592 class U { |
| 3593 A get a => new B(); |
| 3594 } |
| 3595 '''); |
| 3596 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3597 expect(info.superToSubs.keys, isEmpty); |
| 3598 expect(info.instantiatedNames, unorderedEquals(['B'])); |
| 3599 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3600 expect(info.userToDependsOn['U'], unorderedEquals(['A'])); |
| 3601 } |
| 3602 |
| 3603 test_class_members() { |
| 3604 ReferencedNames info = _computeReferencedNames(''' |
| 3605 class U { |
| 3606 int a; |
| 3607 int get b; |
| 3608 set c(_) {} |
| 3609 m(D d) { |
| 3610 a; |
| 3611 b; |
| 3612 c = 1; |
| 3613 m(); |
| 3614 } |
| 3615 } |
| 3616 '''); |
| 3617 expect(info.names, unorderedEquals(['int', 'D'])); |
| 3618 expect(info.superToSubs.keys, isEmpty); |
| 3619 expect(info.instantiatedNames, isEmpty); |
| 3620 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3621 expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D'])); |
| 3622 } |
| 3623 |
| 3624 test_class_members_dontHideQualified() { |
| 3625 ReferencedNames info = _computeReferencedNames(''' |
| 3626 class U { |
| 3627 int a; |
| 3628 int get b; |
| 3629 set c(_) {} |
| 3630 m(D d) { |
| 3631 d.a; |
| 3632 d.b; |
| 3633 d.c; |
| 3634 } |
| 3635 } |
| 3636 '''); |
| 3637 expect(info.names, unorderedEquals(['int', 'D', 'a', 'b', 'c'])); |
| 3638 expect(info.superToSubs.keys, isEmpty); |
| 3639 expect(info.instantiatedNames, isEmpty); |
| 3640 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3641 expect(info.userToDependsOn['U'], unorderedEquals(['int', 'D'])); |
| 3642 } |
| 3643 |
| 3644 test_class_method() { |
| 3645 ReferencedNames info = _computeReferencedNames(''' |
| 3646 class U { |
| 3647 A m(B p) { |
| 3648 C v = 0; |
| 3649 } |
| 3650 } |
| 3651 '''); |
| 3652 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3653 expect(info.superToSubs.keys, isEmpty); |
| 3654 expect(info.instantiatedNames, isEmpty); |
| 3655 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3656 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B'])); |
| 3657 } |
| 3658 |
| 3659 test_class_method_localVariables() { |
| 3660 ReferencedNames info = _computeReferencedNames(''' |
| 3661 class U { |
| 3662 A m() { |
| 3663 B b = null; |
| 3664 b; |
| 3665 { |
| 3666 C c = null; |
| 3667 b; |
| 3668 c; |
| 3669 } |
| 3670 d; |
| 3671 } |
| 3672 } |
| 3673 '''); |
| 3674 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd'])); |
| 3675 expect(info.superToSubs.keys, isEmpty); |
| 3676 expect(info.instantiatedNames, isEmpty); |
| 3677 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3678 expect(info.userToDependsOn['U'], unorderedEquals(['A'])); |
| 3679 } |
| 3680 |
| 3681 test_class_method_parameters() { |
| 3682 ReferencedNames info = _computeReferencedNames(''' |
| 3683 class U { |
| 3684 m(A a) { |
| 3685 a; |
| 3686 b; |
| 3687 } |
| 3688 } |
| 3689 '''); |
| 3690 expect(info.names, unorderedEquals(['A', 'b'])); |
| 3691 expect(info.superToSubs.keys, isEmpty); |
| 3692 expect(info.instantiatedNames, isEmpty); |
| 3693 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3694 expect(info.userToDependsOn['U'], unorderedEquals(['A'])); |
| 3695 } |
| 3696 |
| 3697 test_class_method_typeParameters() { |
| 3698 ReferencedNames info = _computeReferencedNames(''' |
| 3699 class U { |
| 3700 A m<T>(B b, T t) { |
| 3701 C c = 0; |
| 3702 } |
| 3703 } |
| 3704 '''); |
| 3705 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3706 expect(info.superToSubs.keys, isEmpty); |
| 3707 expect(info.instantiatedNames, isEmpty); |
| 3708 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3709 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B'])); |
| 3710 } |
| 3711 |
| 3712 test_class_setter() { |
| 3713 ReferencedNames info = _computeReferencedNames(''' |
| 3714 class U { |
| 3715 set a(A a) { |
| 3716 B b = null; |
| 3717 } |
| 3718 } |
| 3719 '''); |
| 3720 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3721 expect(info.superToSubs.keys, isEmpty); |
| 3722 expect(info.instantiatedNames, isEmpty); |
| 3723 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3724 expect(info.userToDependsOn['U'], unorderedEquals(['A'])); |
| 3725 } |
| 3726 |
| 3727 test_class_typeParameters() { |
| 3728 ReferencedNames info = _computeReferencedNames(''' |
| 3729 class U<T> { |
| 3730 T f = new A<T>(); |
| 3731 } |
| 3732 '''); |
| 3733 expect(info.names, unorderedEquals(['A'])); |
| 3734 expect(info.superToSubs.keys, isEmpty); |
| 3735 expect(info.instantiatedNames, unorderedEquals(['A'])); |
| 3736 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3737 expect(info.userToDependsOn['U'], unorderedEquals(['A'])); |
| 3738 } |
| 3739 |
| 3740 test_instantiatedNames_importPrefix() { |
| 3741 ReferencedNames info = _computeReferencedNames(''' |
| 3742 import 'a.dart' as p1; |
| 3743 import 'b.dart' as p2; |
| 3744 main() { |
| 3745 new p1.A(); |
| 3746 new p1.A.c1(); |
| 3747 new p1.B(); |
| 3748 new p2.C(); |
| 3749 new D(); |
| 3750 new D.c2(); |
| 3751 } |
| 3752 '''); |
| 3753 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D', 'c1', 'c2'])); |
| 3754 expect(info.superToSubs.keys, isEmpty); |
| 3755 expect(info.instantiatedNames, unorderedEquals(['A', 'B', 'C', 'D'])); |
| 3756 expect(info.userToDependsOn.keys, unorderedEquals(['main'])); |
| 3757 expect(info.userToDependsOn['main'], isEmpty); |
| 3758 } |
| 3759 |
| 3760 test_localFunction() { |
| 3761 ReferencedNames info = _computeReferencedNames(''' |
| 3762 f(A a) { |
| 3763 g(B b) {} |
| 3764 } |
| 3765 '''); |
| 3766 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3767 expect(info.superToSubs.keys, isEmpty); |
| 3768 expect(info.instantiatedNames, isEmpty); |
| 3769 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3770 expect(info.userToDependsOn['f'], unorderedEquals(['A'])); |
| 3771 } |
| 3772 |
| 3773 test_superToSubs_importPrefix() { |
| 3774 ReferencedNames info = _computeReferencedNames(''' |
| 3775 import 'a.dart' as p1; |
| 3776 import 'b.dart' as p2; |
| 3777 class U extends p1.A with p2.B implements p2.C {} |
| 3778 '''); |
| 3779 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3780 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C'])); |
| 3781 expect(info.superToSubs['A'], unorderedEquals(['U'])); |
| 3782 expect(info.superToSubs['B'], unorderedEquals(['U'])); |
| 3783 expect(info.superToSubs['C'], unorderedEquals(['U'])); |
| 3784 expect(info.instantiatedNames, isEmpty); |
| 3785 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3786 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C'])); |
| 3787 } |
| 3788 |
| 3789 test_topLevelVariable() { |
| 3790 ReferencedNames info = _computeReferencedNames(''' |
| 3791 A v = new B(c); |
| 3792 '''); |
| 3793 expect(info.names, unorderedEquals(['A', 'B', 'c'])); |
| 3794 expect(info.superToSubs.keys, isEmpty); |
| 3795 expect(info.instantiatedNames, unorderedEquals(['B'])); |
| 3796 expect(info.userToDependsOn.keys, unorderedEquals(['v'])); |
| 3797 expect(info.userToDependsOn['v'], unorderedEquals(['A', 'B', 'c'])); |
| 3798 } |
| 3799 |
| 3800 test_topLevelVariable_multiple() { |
| 3801 ReferencedNames info = _computeReferencedNames(''' |
| 3802 A v1 = new B(c), v2 = new D<E>(f); |
| 3803 '''); |
| 3804 expect(info.names, unorderedEquals(['A', 'B', 'c', 'D', 'E', 'f'])); |
| 3805 expect(info.superToSubs.keys, isEmpty); |
| 3806 expect(info.instantiatedNames, unorderedEquals(['B', 'D'])); |
| 3807 expect(info.userToDependsOn.keys, unorderedEquals(['v1', 'v2'])); |
| 3808 expect(info.userToDependsOn['v1'], unorderedEquals(['A', 'B', 'c'])); |
| 3809 expect(info.userToDependsOn['v2'], unorderedEquals(['A', 'D', 'E', 'f'])); |
| 3810 } |
| 3811 |
| 3812 test_unit_classTypeAlias() { |
| 3813 ReferencedNames info = _computeReferencedNames(''' |
| 3814 class U = A with B implements C; |
| 3815 '''); |
| 3816 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3817 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C'])); |
| 3818 expect(info.superToSubs['A'], unorderedEquals(['U'])); |
| 3819 expect(info.superToSubs['B'], unorderedEquals(['U'])); |
| 3820 expect(info.superToSubs['C'], unorderedEquals(['U'])); |
| 3821 expect(info.instantiatedNames, isEmpty); |
| 3822 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3823 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C'])); |
| 3824 } |
| 3825 |
| 3826 test_unit_classTypeAlias_typeParameters() { |
| 3827 ReferencedNames info = _computeReferencedNames(''' |
| 3828 class U<T1, T2 extends D> = A<T1> with B<T2> implements C<T1, T2>; |
| 3829 '''); |
| 3830 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D'])); |
| 3831 expect(info.superToSubs.keys, unorderedEquals(['A', 'B', 'C'])); |
| 3832 expect(info.superToSubs['A'], unorderedEquals(['U'])); |
| 3833 expect(info.superToSubs['B'], unorderedEquals(['U'])); |
| 3834 expect(info.superToSubs['C'], unorderedEquals(['U'])); |
| 3835 expect(info.instantiatedNames, isEmpty); |
| 3836 expect(info.userToDependsOn.keys, unorderedEquals(['U'])); |
| 3837 expect(info.userToDependsOn['U'], unorderedEquals(['A', 'B', 'C', 'D'])); |
| 3838 } |
| 3839 |
| 3840 test_unit_function() { |
| 3841 ReferencedNames info = _computeReferencedNames(''' |
| 3842 A f(B b) { |
| 3843 C c = 0; |
| 3844 } |
| 3845 '''); |
| 3846 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3847 expect(info.superToSubs.keys, isEmpty); |
| 3848 expect(info.instantiatedNames, isEmpty); |
| 3849 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3850 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B'])); |
| 3851 } |
| 3852 |
| 3853 test_unit_function_doc() { |
| 3854 ReferencedNames info = _computeReferencedNames(''' |
| 3855 /** |
| 3856 * Documentation [C.d] reference. |
| 3857 */ |
| 3858 A f(B b) {} |
| 3859 '''); |
| 3860 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd'])); |
| 3861 expect(info.superToSubs.keys, isEmpty); |
| 3862 expect(info.instantiatedNames, isEmpty); |
| 3863 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3864 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B'])); |
| 3865 } |
| 3866 |
| 3867 test_unit_function_localFunctions() { |
| 3868 ReferencedNames info = _computeReferencedNames(''' |
| 3869 A f() { |
| 3870 B b = null; |
| 3871 C g() {} |
| 3872 g(); |
| 3873 } |
| 3874 '''); |
| 3875 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3876 expect(info.superToSubs.keys, isEmpty); |
| 3877 expect(info.instantiatedNames, isEmpty); |
| 3878 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3879 expect(info.userToDependsOn['f'], unorderedEquals(['A'])); |
| 3880 } |
| 3881 |
| 3882 test_unit_function_localsDontHideQualified() { |
| 3883 ReferencedNames info = _computeReferencedNames(''' |
| 3884 f(A a, B b) { |
| 3885 var v = 0; |
| 3886 a.v; |
| 3887 a.b; |
| 3888 } |
| 3889 '''); |
| 3890 expect(info.names, unorderedEquals(['A', 'B', 'v', 'b'])); |
| 3891 expect(info.superToSubs.keys, isEmpty); |
| 3892 expect(info.instantiatedNames, isEmpty); |
| 3893 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3894 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B'])); |
| 3895 } |
| 3896 |
| 3897 test_unit_function_localVariables() { |
| 3898 ReferencedNames info = _computeReferencedNames(''' |
| 3899 A f() { |
| 3900 B b = null; |
| 3901 b; |
| 3902 { |
| 3903 C c = null; |
| 3904 b; |
| 3905 c; |
| 3906 } |
| 3907 d; |
| 3908 } |
| 3909 '''); |
| 3910 expect(info.names, unorderedEquals(['A', 'B', 'C', 'd'])); |
| 3911 expect(info.superToSubs.keys, isEmpty); |
| 3912 expect(info.instantiatedNames, isEmpty); |
| 3913 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3914 expect(info.userToDependsOn['f'], unorderedEquals(['A'])); |
| 3915 } |
| 3916 |
| 3917 test_unit_function_parameters() { |
| 3918 ReferencedNames info = _computeReferencedNames(''' |
| 3919 A f(B b) { |
| 3920 C c = 0; |
| 3921 b; |
| 3922 } |
| 3923 '''); |
| 3924 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3925 expect(info.superToSubs.keys, isEmpty); |
| 3926 expect(info.instantiatedNames, isEmpty); |
| 3927 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3928 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B'])); |
| 3929 } |
| 3930 |
| 3931 test_unit_function_typeParameters() { |
| 3932 ReferencedNames info = _computeReferencedNames(''' |
| 3933 A f<T>(B b, T t) { |
| 3934 C c = 0; |
| 3935 } |
| 3936 '''); |
| 3937 expect(info.names, unorderedEquals(['A', 'B', 'C'])); |
| 3938 expect(info.superToSubs.keys, isEmpty); |
| 3939 expect(info.instantiatedNames, isEmpty); |
| 3940 expect(info.userToDependsOn.keys, unorderedEquals(['f'])); |
| 3941 expect(info.userToDependsOn['f'], unorderedEquals(['A', 'B'])); |
| 3942 } |
| 3943 |
| 3944 test_unit_functionTypeAlias() { |
| 3945 ReferencedNames info = _computeReferencedNames(''' |
| 3946 typedef A F(B B, C c(D d)); |
| 3947 '''); |
| 3948 expect(info.names, unorderedEquals(['A', 'B', 'C', 'D'])); |
| 3949 expect(info.superToSubs.keys, isEmpty); |
| 3950 expect(info.instantiatedNames, isEmpty); |
| 3951 expect(info.userToDependsOn.keys, unorderedEquals(['F'])); |
| 3952 expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B', 'C', 'D'])); |
| 3953 } |
| 3954 |
| 3955 test_unit_functionTypeAlias_typeParameters() { |
| 3956 ReferencedNames info = _computeReferencedNames(''' |
| 3957 typedef A F<T>(B b, T t); |
| 3958 '''); |
| 3959 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3960 expect(info.superToSubs.keys, isEmpty); |
| 3961 expect(info.instantiatedNames, isEmpty); |
| 3962 expect(info.userToDependsOn.keys, unorderedEquals(['F'])); |
| 3963 expect(info.userToDependsOn['F'], unorderedEquals(['A', 'B'])); |
| 3964 } |
| 3965 |
| 3966 test_unit_getter() { |
| 3967 ReferencedNames info = _computeReferencedNames(''' |
| 3968 A get aaa { |
| 3969 return new B(); |
| 3970 } |
| 3971 '''); |
| 3972 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3973 expect(info.superToSubs.keys, isEmpty); |
| 3974 expect(info.instantiatedNames, unorderedEquals(['B'])); |
| 3975 expect(info.userToDependsOn.keys, unorderedEquals(['aaa'])); |
| 3976 expect(info.userToDependsOn['aaa'], unorderedEquals(['A'])); |
| 3977 } |
| 3978 |
| 3979 test_unit_setter() { |
| 3980 ReferencedNames info = _computeReferencedNames(''' |
| 3981 set aaa(A a) { |
| 3982 B b = null; |
| 3983 } |
| 3984 '''); |
| 3985 expect(info.names, unorderedEquals(['A', 'B'])); |
| 3986 expect(info.superToSubs.keys, isEmpty); |
| 3987 expect(info.instantiatedNames, isEmpty); |
| 3988 expect(info.userToDependsOn.keys, unorderedEquals(['aaa'])); |
| 3989 expect(info.userToDependsOn['aaa'], unorderedEquals(['A'])); |
| 3990 } |
| 3991 |
| 3992 ReferencedNames _computeReferencedNames(String code) { |
| 3993 Source source = newSource('/test.dart', code); |
| 3994 computeResult(source, REFERENCED_NAMES, matcher: isParseDartTask); |
| 3995 return outputs[REFERENCED_NAMES]; |
| 3996 } |
| 3997 } |
| 3998 |
| 3999 @reflectiveTest |
| 4000 class ResolveDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 4001 test_perform() { |
| 4002 List<Source> sources = newSources({ |
| 4003 '/libA.dart': ''' |
| 4004 library libA; |
| 4005 import 'libB.dart'; |
| 4006 export 'libC.dart'; |
| 4007 ''', |
| 4008 '/libB.dart': ''' |
| 4009 library libB; |
| 4010 ''', |
| 4011 '/libC.dart': ''' |
| 4012 library libC; |
| 4013 ''' |
| 4014 }); |
| 4015 Source sourceA = sources[0]; |
| 4016 LibrarySpecificUnit targetA = new LibrarySpecificUnit(sourceA, sourceA); |
| 4017 // build directive elements |
| 4018 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 4019 matcher: isBuildDirectiveElementsTask); |
| 4020 // prepare outputs |
| 4021 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; |
| 4022 LibraryElement libraryElementB = libraryElementA.imports[0].importedLibrary; |
| 4023 LibraryElement libraryElementC = libraryElementA.exports[0].exportedLibrary; |
| 4024 // clear elements in directive ASTs |
| 4025 { |
| 4026 CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT1); |
| 4027 unitA.directives[1].element = null; |
| 4028 unitA.directives[2].element = null; |
| 4029 } |
| 4030 // resolve directive ASTs |
| 4031 computeResult(targetA, RESOLVED_UNIT2, |
| 4032 matcher: isResolveDirectiveElementsTask); |
| 4033 // validate that directive ASTs have elements |
| 4034 CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT2); |
| 4035 { |
| 4036 ImportDirective importNode = unitA.directives[1]; |
| 4037 ImportElement importElement = importNode.element; |
| 4038 expect(importElement, isNotNull); |
| 4039 expect(importElement.importedLibrary, libraryElementB); |
| 4040 } |
| 4041 { |
| 4042 ExportDirective exportNode = unitA.directives[2]; |
| 4043 ExportElement exportElement = exportNode.element; |
| 4044 expect(exportElement, isNotNull); |
| 4045 expect(exportElement.exportedLibrary, libraryElementC); |
| 4046 } |
| 4047 } |
| 4048 } |
| 4049 |
| 4050 @reflectiveTest |
| 2954 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { | 4051 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { |
| 2955 @override | 4052 @override |
| 2956 void setUp() { | 4053 void setUp() { |
| 2957 super.setUp(); | 4054 super.setUp(); |
| 2958 enableStrongMode(); | 4055 enableStrongMode(); |
| 2959 } | 4056 } |
| 2960 | 4057 |
| 4058 test_created_resolved_unit() { |
| 4059 Source source = newSource( |
| 4060 '/test.dart', |
| 4061 r''' |
| 4062 library lib; |
| 4063 class A {} |
| 4064 '''); |
| 4065 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4066 computeResult(target, RESOLVED_UNIT9); |
| 4067 expect(outputs[RESOLVED_UNIT9], isNotNull); |
| 4068 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); |
| 4069 } |
| 4070 |
| 2961 // Test inference of instance fields across units | 4071 // Test inference of instance fields across units |
| 2962 void test_perform_inference_cross_unit_instance() { | 4072 void test_perform_inference_cross_unit_instance() { |
| 2963 List<Source> sources = newSources({ | 4073 List<Source> sources = newSources({ |
| 2964 '/a.dart': ''' | 4074 '/a.dart': ''' |
| 2965 import 'b.dart'; | 4075 import 'b.dart'; |
| 2966 class A { | 4076 class A { |
| 2967 final a2 = new B().b2; | 4077 final a2 = new B().b2; |
| 2968 } | 4078 } |
| 2969 ''', | 4079 ''', |
| 2970 '/b.dart': ''' | 4080 '/b.dart': ''' |
| 2971 class B { | 4081 class B { |
| 2972 final b2 = 1; | 4082 final b2 = 1; |
| 2973 } | 4083 } |
| 2974 ''', | 4084 ''', |
| 2975 '/main.dart': ''' | 4085 '/main.dart': ''' |
| 2976 import "a.dart"; | 4086 import "a.dart"; |
| 2977 | 4087 |
| 2978 test1() { | 4088 test1() { |
| 2979 int x = 0; | 4089 int x = 0; |
| 2980 x = new A().a2; | 4090 x = new A().a2; |
| 2981 } | 4091 } |
| 2982 ''' | 4092 ''' |
| 2983 }); | 4093 }); |
| 2984 InterfaceType intType = context.typeProvider.intType; | 4094 InterfaceType intType = context.typeProvider.intType; |
| 2985 DartType dynamicType = context.typeProvider.dynamicType; | 4095 DartType dynamicType = context.typeProvider.dynamicType; |
| 2986 | 4096 |
| 2987 computeResult( | 4097 computeResult( |
| 2988 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); | 4098 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9); |
| 2989 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; | 4099 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; |
| 2990 | 4100 |
| 2991 // B.b2 shoud be resolved on the rhs, but not yet inferred. | 4101 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 2992 assertVariableDeclarationTypes( | 4102 assertVariableDeclarationTypes( |
| 2993 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); | 4103 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 2994 | 4104 |
| 2995 computeResult( | 4105 computeResult( |
| 2996 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); | 4106 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9); |
| 2997 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; | 4107 CompilationUnit unit0 = outputs[RESOLVED_UNIT9]; |
| 2998 | 4108 |
| 2999 // B.b2 should now be fully resolved and inferred. | 4109 // B.b2 should now be fully resolved and inferred. |
| 3000 assertVariableDeclarationTypes( | 4110 assertVariableDeclarationTypes( |
| 3001 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4111 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3002 | 4112 |
| 3003 // A.a2 should now be resolved on the rhs, but not yet inferred. | 4113 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3004 assertVariableDeclarationTypes( | 4114 assertVariableDeclarationTypes( |
| 3005 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 4115 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3006 | 4116 |
| 3007 computeResult( | 4117 computeResult( |
| 3008 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); | 4118 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 3009 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; | |
| 3010 | 4119 |
| 3011 // A.a2 should now be fully resolved and inferred. | 4120 // A.a2 should now be fully resolved and inferred. |
| 3012 assertVariableDeclarationTypes( | 4121 assertVariableDeclarationTypes( |
| 3013 getFieldInClass(unit0, "A", "a2"), intType, intType); | 4122 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3014 | 4123 |
| 3015 assertVariableDeclarationTypes( | 4124 assertVariableDeclarationTypes( |
| 3016 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4125 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3017 } | 4126 } |
| 3018 | 4127 |
| 3019 // Test inference of instance fields across units | 4128 // Test inference of instance fields across units |
| 3020 void test_perform_inference_cross_unit_instance_cyclic() { | 4129 void test_perform_inference_cross_unit_instance_cyclic() { |
| 3021 List<Source> sources = newSources({ | 4130 List<Source> sources = newSources({ |
| 3022 '/a.dart': ''' | 4131 '/a.dart': ''' |
| 3023 import 'b.dart'; | 4132 import 'b.dart'; |
| 3024 class A { | 4133 class A { |
| 3025 final a2 = new B().b2; | 4134 final a2 = new B().b2; |
| 3026 } | 4135 } |
| 3027 ''', | 4136 ''', |
| 3028 '/b.dart': ''' | 4137 '/b.dart': ''' |
| 3029 import 'a.dart'; | 4138 import 'a.dart'; |
| 3030 class B { | 4139 class B { |
| 3031 final b2 = 1; | 4140 final b2 = 1; |
| 3032 } | 4141 } |
| 3033 ''', | 4142 ''', |
| 3034 '/main.dart': ''' | 4143 '/main.dart': ''' |
| 3035 import "a.dart"; | 4144 import "a.dart"; |
| 3036 | 4145 |
| 3037 test1() { | 4146 test1() { |
| 3038 int x = 0; | 4147 int x = 0; |
| 3039 x = new A().a2; | 4148 x = new A().a2; |
| 3040 } | 4149 } |
| 3041 ''' | 4150 ''' |
| 3042 }); | 4151 }); |
| 3043 InterfaceType intType = context.typeProvider.intType; | |
| 3044 DartType dynamicType = context.typeProvider.dynamicType; | 4152 DartType dynamicType = context.typeProvider.dynamicType; |
| 3045 | 4153 |
| 3046 computeResult( | 4154 computeResult( |
| 3047 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); | 4155 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9); |
| 3048 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; | 4156 CompilationUnit unit0 = outputs[RESOLVED_UNIT9]; |
| 3049 | 4157 |
| 3050 // A.a2 should now be resolved on the rhs, but not yet inferred. | 4158 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3051 assertVariableDeclarationTypes( | 4159 assertVariableDeclarationTypes( |
| 3052 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4160 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3053 | 4161 |
| 3054 computeResult( | 4162 computeResult( |
| 3055 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); | 4163 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 3056 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; | |
| 3057 | 4164 |
| 3058 // A.a2 should now be fully resolved and inferred. | 4165 // A.a2 should now be fully resolved and inferred (but not re-resolved). |
| 3059 assertVariableDeclarationTypes( | 4166 assertVariableDeclarationTypes( |
| 3060 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4167 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3061 } | 4168 } |
| 3062 | 4169 |
| 3063 // Test inference of instance fields across units with cycles | 4170 // Test inference of instance fields across units with cycles |
| 3064 void test_perform_inference_cross_unit_static_instance() { | 4171 void test_perform_inference_cross_unit_static_instance() { |
| 3065 List<Source> sources = newSources({ | 4172 List<Source> sources = newSources({ |
| 3066 '/a.dart': ''' | 4173 '/a.dart': ''' |
| 3067 import 'b.dart'; | 4174 import 'b.dart'; |
| 3068 class A { | 4175 class A { |
| 3069 static final a1 = B.b1; | 4176 static final a1 = B.b1; |
| 3070 final a2 = new B().b2; | 4177 final a2 = new B().b2; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3084 // inference in A now works. | 4191 // inference in A now works. |
| 3085 x = A.a1; | 4192 x = A.a1; |
| 3086 x = new A().a2; | 4193 x = new A().a2; |
| 3087 } | 4194 } |
| 3088 ''' | 4195 ''' |
| 3089 }); | 4196 }); |
| 3090 InterfaceType intType = context.typeProvider.intType; | 4197 InterfaceType intType = context.typeProvider.intType; |
| 3091 DartType dynamicType = context.typeProvider.dynamicType; | 4198 DartType dynamicType = context.typeProvider.dynamicType; |
| 3092 | 4199 |
| 3093 computeResult( | 4200 computeResult( |
| 3094 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); | 4201 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9); |
| 3095 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; | 4202 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; |
| 3096 | 4203 |
| 3097 assertVariableDeclarationTypes( | 4204 assertVariableDeclarationTypes( |
| 3098 getFieldInClass(unit1, "B", "b1"), intType, intType); | 4205 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3099 assertVariableDeclarationTypes( | 4206 assertVariableDeclarationTypes( |
| 3100 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); | 4207 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); |
| 3101 | 4208 |
| 3102 computeResult( | 4209 computeResult( |
| 3103 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); | 4210 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9); |
| 3104 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; | 4211 CompilationUnit unit0 = outputs[RESOLVED_UNIT9]; |
| 3105 | 4212 |
| 3106 assertVariableDeclarationTypes( | 4213 assertVariableDeclarationTypes( |
| 3107 getFieldInClass(unit0, "A", "a1"), intType, intType); | 4214 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3108 assertVariableDeclarationTypes( | 4215 assertVariableDeclarationTypes( |
| 3109 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 4216 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3110 | 4217 |
| 3111 assertVariableDeclarationTypes( | 4218 assertVariableDeclarationTypes( |
| 3112 getFieldInClass(unit1, "B", "b1"), intType, intType); | 4219 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3113 assertVariableDeclarationTypes( | 4220 assertVariableDeclarationTypes( |
| 3114 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4221 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3115 | 4222 |
| 3116 computeResult( | 4223 computeResult( |
| 3117 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); | 4224 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
| 3118 CompilationUnit unit2 = outputs[RESOLVED_UNIT7]; | |
| 3119 | 4225 |
| 3120 assertVariableDeclarationTypes( | 4226 assertVariableDeclarationTypes( |
| 3121 getFieldInClass(unit0, "A", "a1"), intType, intType); | 4227 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3122 assertVariableDeclarationTypes( | 4228 assertVariableDeclarationTypes( |
| 3123 getFieldInClass(unit0, "A", "a2"), intType, intType); | 4229 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3124 | 4230 |
| 3125 assertVariableDeclarationTypes( | 4231 assertVariableDeclarationTypes( |
| 3126 getFieldInClass(unit1, "B", "b1"), intType, intType); | 4232 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3127 assertVariableDeclarationTypes( | 4233 assertVariableDeclarationTypes( |
| 3128 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4234 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3129 } | 4235 } |
| 3130 | 4236 |
| 3131 // Test inference between static and instance fields | 4237 // Test inference between static and instance fields |
| 3132 void test_perform_inference_instance() { | 4238 void test_perform_inference_instance() { |
| 3133 List<Source> sources = newSources({ | 4239 List<Source> sources = newSources({ |
| 3134 '/a.dart': ''' | 4240 '/a.dart': ''' |
| 3135 import 'b.dart'; | 4241 import 'b.dart'; |
| 3136 class A { | 4242 class A { |
| 3137 final a2 = new B().b2; | 4243 final a2 = new B().b2; |
| 3138 } | 4244 } |
| 3139 | 4245 |
| 3140 class B { | 4246 class B { |
| 3141 final b2 = 1; | 4247 final b2 = 1; |
| 3142 } | 4248 } |
| 3143 ''', | 4249 ''', |
| 3144 '/main.dart': ''' | 4250 '/main.dart': ''' |
| 3145 import "a.dart"; | 4251 import "a.dart"; |
| 3146 | 4252 |
| 3147 test1() { | 4253 test1() { |
| 3148 int x = 0; | 4254 int x = 0; |
| 3149 x = new A().a2; | 4255 x = new A().a2; |
| 3150 } | 4256 } |
| 3151 ''' | 4257 ''' |
| 3152 }); | 4258 }); |
| 3153 InterfaceType intType = context.typeProvider.intType; | 4259 InterfaceType intType = context.typeProvider.intType; |
| 3154 DartType dynamicType = context.typeProvider.dynamicType; | 4260 DartType dynamicType = context.typeProvider.dynamicType; |
| 3155 | 4261 |
| 3156 computeResult( | 4262 computeResult( |
| 3157 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); | 4263 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9); |
| 3158 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; | 4264 CompilationUnit unit0 = outputs[RESOLVED_UNIT9]; |
| 3159 | 4265 |
| 3160 // A.a2 should now be resolved on the rhs, but not yet inferred. | 4266 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3161 assertVariableDeclarationTypes( | 4267 assertVariableDeclarationTypes( |
| 3162 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4268 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3163 | 4269 |
| 3164 // B.b2 shoud be resolved on the rhs, but not yet inferred. | 4270 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 3165 assertVariableDeclarationTypes( | 4271 assertVariableDeclarationTypes( |
| 3166 getFieldInClass(unit0, "B", "b2"), dynamicType, intType); | 4272 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType); |
| 3167 | 4273 |
| 3168 computeResult( | 4274 computeResult( |
| 3169 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); | 4275 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9); |
| 3170 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; | |
| 3171 | 4276 |
| 3172 // A.a2 should now be fully resolved and inferred. | 4277 // A.a2 should now be fully resolved and inferred (but not re-resolved). |
| 3173 assertVariableDeclarationTypes( | 4278 assertVariableDeclarationTypes( |
| 3174 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 4279 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3175 | 4280 |
| 3176 // B.b2 should now be fully resolved and inferred. | 4281 // B.b2 should now be fully resolved and inferred. |
| 3177 assertVariableDeclarationTypes( | 4282 assertVariableDeclarationTypes( |
| 3178 getFieldInClass(unit0, "B", "b2"), intType, intType); | 4283 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 3179 } | 4284 } |
| 3180 } | 4285 } |
| 3181 | 4286 |
| 4287 @reflectiveTest |
| 4288 class ResolveLibraryTaskTest extends _AbstractDartTaskTest { |
| 4289 test_perform() { |
| 4290 Source sourceLib = newSource( |
| 4291 '/my_lib.dart', |
| 4292 ''' |
| 4293 library my_lib; |
| 4294 const a = new A(); |
| 4295 class A { |
| 4296 const A(); |
| 4297 } |
| 4298 @a |
| 4299 class C {} |
| 4300 '''); |
| 4301 computeResult(sourceLib, LIBRARY_ELEMENT, matcher: isResolveLibraryTask); |
| 4302 // validate |
| 4303 LibraryElement library = outputs[LIBRARY_ELEMENT]; |
| 4304 ClassElement classC = library.getType('C'); |
| 4305 List<ElementAnnotation> metadata = classC.metadata; |
| 4306 expect(metadata, hasLength(1)); |
| 4307 ElementAnnotation annotation = metadata[0]; |
| 4308 expect(annotation, isNotNull); |
| 4309 expect((annotation as ElementAnnotationImpl).evaluationResult, isNotNull); |
| 4310 } |
| 4311 } |
| 4312 |
| 3182 @reflectiveTest | 4313 @reflectiveTest |
| 3183 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { | 4314 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 3184 test_perform() { | 4315 test_perform() { |
| 3185 Source sourceLib = newSource( | 4316 Source sourceLib = newSource( |
| 3186 '/my_lib.dart', | 4317 '/my_lib.dart', |
| 3187 ''' | 4318 ''' |
| 3188 library my_lib; | 4319 library my_lib; |
| 3189 part 'my_part.dart'; | 4320 part 'my_part.dart'; |
| 3190 class A {} | 4321 class A {} |
| 3191 class B extends A {} | 4322 class B extends A {} |
| 3192 '''); | 4323 '''); |
| 3193 newSource( | 4324 newSource( |
| 3194 '/my_part.dart', | 4325 '/my_part.dart', |
| 3195 ''' | 4326 ''' |
| 3196 part of my_lib; | 4327 part of my_lib; |
| 3197 class C extends A {} | 4328 class C extends A {} |
| 3198 '''); | 4329 '''); |
| 3199 computeResult(sourceLib, LIBRARY_ELEMENT5, | 4330 computeResult(sourceLib, LIBRARY_ELEMENT6, |
| 3200 matcher: isResolveLibraryTypeNamesTask); | 4331 matcher: isResolveLibraryTypeNamesTask); |
| 3201 // validate | 4332 // validate |
| 3202 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 4333 LibraryElement library = outputs[LIBRARY_ELEMENT6]; |
| 3203 { | 4334 { |
| 3204 ClassElement classB = library.getType('B'); | 4335 ClassElement classB = library.getType('B'); |
| 3205 expect(classB.supertype.displayName, 'A'); | 4336 expect(classB.supertype.displayName, 'A'); |
| 3206 } | 4337 } |
| 3207 { | 4338 { |
| 3208 ClassElement classC = library.getType('C'); | 4339 ClassElement classC = library.getType('C'); |
| 3209 expect(classC.supertype.displayName, 'A'); | 4340 expect(classC.supertype.displayName, 'A'); |
| 3210 } | 4341 } |
| 4342 expect(library.loadLibraryFunction, isNotNull); |
| 3211 } | 4343 } |
| 3212 | 4344 |
| 3213 test_perform_external() { | 4345 test_perform_external() { |
| 3214 Source sourceA = newSource( | 4346 Source sourceA = newSource( |
| 3215 '/a.dart', | 4347 '/a.dart', |
| 3216 ''' | 4348 ''' |
| 3217 library a; | 4349 library a; |
| 3218 import 'b.dart'; | 4350 import 'b.dart'; |
| 3219 class A extends B {} | 4351 class A extends B {} |
| 3220 '''); | 4352 '''); |
| 3221 newSource( | 4353 newSource( |
| 3222 '/b.dart', | 4354 '/b.dart', |
| 3223 ''' | 4355 ''' |
| 3224 library b; | 4356 library b; |
| 3225 class B {} | 4357 class B {} |
| 3226 '''); | 4358 '''); |
| 3227 // The reference A to B should be resolved, but there's no requirement that | 4359 // The reference A to B should be resolved, but there's no requirement that |
| 3228 // the full class hierarchy be resolved. | 4360 // the full class hierarchy be resolved. |
| 3229 computeResult(sourceA, LIBRARY_ELEMENT5, | 4361 computeResult(sourceA, LIBRARY_ELEMENT6, |
| 3230 matcher: isResolveLibraryTypeNamesTask); | 4362 matcher: isResolveLibraryTypeNamesTask); |
| 3231 // validate | 4363 // validate |
| 3232 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 4364 LibraryElement library = outputs[LIBRARY_ELEMENT6]; |
| 3233 { | 4365 { |
| 3234 ClassElement clazz = library.getType('A'); | 4366 ClassElement clazz = library.getType('A'); |
| 3235 expect(clazz.displayName, 'A'); | 4367 expect(clazz.displayName, 'A'); |
| 3236 clazz = clazz.supertype.element; | 4368 clazz = clazz.supertype.element; |
| 3237 expect(clazz.displayName, 'B'); | 4369 expect(clazz.displayName, 'B'); |
| 3238 } | 4370 } |
| 3239 } | 4371 } |
| 3240 } | 4372 } |
| 3241 | 4373 |
| 3242 @reflectiveTest | 4374 @reflectiveTest |
| 4375 class ResolveTopLevelUnitTypeBoundsTaskTest extends _AbstractDartTaskTest { |
| 4376 test_perform_boundIsGenericType() { |
| 4377 Source source = newSource( |
| 4378 '/test.dart', |
| 4379 ''' |
| 4380 class C<T extends Map<String, List<int>>> {} |
| 4381 '''); |
| 4382 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4383 computeResult(target, RESOLVED_UNIT4, |
| 4384 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4385 // validate |
| 4386 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4387 ClassDeclaration nodeC = unit.declarations[0]; |
| 4388 _assertTypeParameterBound(nodeC.typeParameters.typeParameters[0], |
| 4389 'Map<String, List<int>>', 'Map'); |
| 4390 } |
| 4391 |
| 4392 test_perform_errors() { |
| 4393 Source source = newSource( |
| 4394 '/test.dart', |
| 4395 ''' |
| 4396 class C<T extends NoSuchClass> {} |
| 4397 '''); |
| 4398 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4399 computeResult(target, RESOLVE_TYPE_BOUNDS_ERRORS, |
| 4400 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4401 // validate |
| 4402 _fillErrorListener(RESOLVE_TYPE_BOUNDS_ERRORS); |
| 4403 errorListener |
| 4404 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 4405 } |
| 4406 |
| 4407 test_perform_ignoreBoundsOfBounds() { |
| 4408 Source source = newSource( |
| 4409 '/test.dart', |
| 4410 ''' |
| 4411 class A<T1 extends num> {} |
| 4412 class B<T2 extends A> {} |
| 4413 '''); |
| 4414 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4415 computeResult(target, RESOLVED_UNIT4, |
| 4416 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4417 // validate |
| 4418 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4419 ClassDeclaration nodeB = unit.declarations[1]; |
| 4420 _assertTypeParameterBound( |
| 4421 nodeB.typeParameters.typeParameters[0], 'A<dynamic>', 'A'); |
| 4422 } |
| 4423 |
| 4424 test_perform_outputs() { |
| 4425 Source source = newSource( |
| 4426 '/test.dart', |
| 4427 r''' |
| 4428 class C<T extends int> {} |
| 4429 '''); |
| 4430 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4431 computeResult(target, RESOLVED_UNIT4); |
| 4432 expect(outputs[RESOLVED_UNIT4], isNotNull); |
| 4433 expect(outputs[CREATED_RESOLVED_UNIT4], isTrue); |
| 4434 expect(outputs[RESOLVE_TYPE_BOUNDS_ERRORS], isNotNull); |
| 4435 } |
| 4436 |
| 4437 test_perform_unitMember_ClassDeclaration() { |
| 4438 Source source = newSource( |
| 4439 '/test.dart', |
| 4440 ''' |
| 4441 class C<T extends int> extends Object {} |
| 4442 '''); |
| 4443 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4444 computeResult(target, RESOLVED_UNIT4, |
| 4445 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4446 // validate |
| 4447 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4448 ClassDeclaration nodeC = unit.declarations[0]; |
| 4449 // 'extends Object' is not resolved |
| 4450 expect(nodeC.extendsClause.superclass.name.staticElement, isNull); |
| 4451 // but 'T extends int' is resolved |
| 4452 _assertTypeParameterBound( |
| 4453 nodeC.typeParameters.typeParameters[0], 'int', 'int'); |
| 4454 } |
| 4455 |
| 4456 test_perform_unitMember_ClassTypeAlias() { |
| 4457 Source source = newSource( |
| 4458 '/test.dart', |
| 4459 ''' |
| 4460 class C<T extends double> = Object; |
| 4461 '''); |
| 4462 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4463 computeResult(target, RESOLVED_UNIT4, |
| 4464 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4465 // validate |
| 4466 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4467 ClassTypeAlias nodeC = unit.declarations[0]; |
| 4468 // '= Object' is not resolved |
| 4469 expect(nodeC.superclass.name.staticElement, isNull); |
| 4470 // but 'T extends int' is resolved |
| 4471 _assertTypeParameterBound( |
| 4472 nodeC.typeParameters.typeParameters[0], 'double', 'double'); |
| 4473 } |
| 4474 |
| 4475 test_perform_unitMember_FunctionTypeAlias() { |
| 4476 Source source = newSource( |
| 4477 '/test.dart', |
| 4478 ''' |
| 4479 typedef F<T extends String>(); |
| 4480 '''); |
| 4481 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4482 computeResult(target, RESOLVED_UNIT4, |
| 4483 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4484 // validate |
| 4485 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4486 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 4487 // but 'T extends String' is resolved |
| 4488 _assertTypeParameterBound( |
| 4489 nodeF.typeParameters.typeParameters[0], 'String', 'String'); |
| 4490 } |
| 4491 |
| 4492 void _assertTypeParameterBound(TypeParameter typeParameter, |
| 4493 String expectedBoundTypeString, String expectedBoundElementName) { |
| 4494 TypeName boundNode = typeParameter.bound; |
| 4495 Identifier boundName = boundNode.name; |
| 4496 expect(boundNode.type.toString(), expectedBoundTypeString); |
| 4497 expect(boundName.staticType.toString(), expectedBoundTypeString); |
| 4498 expect(boundName.staticElement.displayName, expectedBoundElementName); |
| 4499 } |
| 4500 } |
| 4501 |
| 4502 @reflectiveTest |
| 3243 class ResolveUnitTaskTest extends _AbstractDartTaskTest { | 4503 class ResolveUnitTaskTest extends _AbstractDartTaskTest { |
| 4504 test_created_resolved_unit() { |
| 4505 Source source = newSource( |
| 4506 '/test.dart', |
| 4507 r''' |
| 4508 library lib; |
| 4509 class A {} |
| 4510 '''); |
| 4511 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4512 computeResult(target, RESOLVED_UNIT11); |
| 4513 expect(outputs[RESOLVED_UNIT11], isNotNull); |
| 4514 expect(outputs[CREATED_RESOLVED_UNIT11], isTrue); |
| 4515 } |
| 4516 |
| 3244 void test_perform() { | 4517 void test_perform() { |
| 3245 AnalysisTarget source = newSource( | 4518 AnalysisTarget source = newSource( |
| 3246 '/test.dart', | 4519 '/test.dart', |
| 3247 ''' | 4520 ''' |
| 3248 void f() { | 4521 void f() { |
| 3249 var c = new C(); | 4522 var c = new C(); |
| 3250 c.m(); | 4523 c.m(); |
| 3251 } | 4524 } |
| 3252 class C { | 4525 class C { |
| 3253 void m() { | 4526 void m() { |
| 3254 f(); | 4527 f(); |
| 3255 } | 4528 } |
| 3256 } | 4529 } |
| 3257 '''); | 4530 '''); |
| 3258 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9, | 4531 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11, |
| 3259 matcher: isResolveUnitTask); | 4532 matcher: isResolveUnitTask); |
| 3260 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 4533 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3261 | 4534 |
| 3262 FunctionDeclaration f = unit.declarations[0]; | 4535 FunctionDeclaration f = unit.declarations[0]; |
| 3263 _assertResolved(f.functionExpression.body); | 4536 _assertResolved(f.functionExpression.body); |
| 3264 | 4537 |
| 3265 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; | 4538 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; |
| 3266 _assertResolved(m.body); | 4539 _assertResolved(m.body); |
| 3267 | 4540 |
| 3268 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0)); | 4541 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0)); |
| 3269 } | 4542 } |
| 3270 | 4543 |
| 3271 void _assertResolved(FunctionBody body) { | 4544 void _assertResolved(FunctionBody body) { |
| 3272 ResolutionVerifier verifier = new ResolutionVerifier(); | 4545 ResolutionVerifier verifier = new ResolutionVerifier(); |
| 3273 body.accept(verifier); | 4546 body.accept(verifier); |
| 3274 verifier.assertResolved(); | 4547 verifier.assertResolved(); |
| 3275 } | 4548 } |
| 3276 } | 4549 } |
| 3277 | 4550 |
| 3278 @reflectiveTest | 4551 @reflectiveTest |
| 3279 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 4552 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 4553 test_created_resolved_unit() { |
| 4554 Source source = newSource( |
| 4555 '/test.dart', |
| 4556 r''' |
| 4557 library lib; |
| 4558 class A {} |
| 4559 '''); |
| 4560 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4561 computeResult(target, RESOLVED_UNIT5); |
| 4562 expect(outputs[RESOLVED_UNIT5], isNotNull); |
| 4563 expect(outputs[CREATED_RESOLVED_UNIT5], isTrue); |
| 4564 } |
| 4565 |
| 3280 test_perform() { | 4566 test_perform() { |
| 3281 Source source = newSource( | 4567 Source source = newSource( |
| 3282 '/test.dart', | 4568 '/test.dart', |
| 3283 ''' | 4569 ''' |
| 3284 class A {} | 4570 class A {} |
| 3285 class B extends A {} | 4571 class B extends A {} |
| 3286 int f(String p) => p.length; | 4572 int f(String p) => p.length; |
| 3287 '''); | 4573 '''); |
| 3288 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4574 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3289 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); | 4575 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); |
| 3290 // validate | 4576 // validate |
| 3291 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 4577 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 3292 { | 4578 { |
| 3293 ClassDeclaration nodeA = unit.declarations[0]; | 4579 ClassDeclaration nodeA = unit.declarations[0]; |
| 3294 ClassDeclaration nodeB = unit.declarations[1]; | 4580 ClassDeclaration nodeB = unit.declarations[1]; |
| 3295 DartType extendsType = nodeB.extendsClause.superclass.type; | 4581 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 3296 expect(extendsType, nodeA.element.type); | 4582 expect(extendsType, nodeA.element.type); |
| 3297 } | 4583 } |
| 3298 { | 4584 { |
| 3299 FunctionDeclaration functionNode = unit.declarations[2]; | 4585 FunctionDeclaration functionNode = unit.declarations[2]; |
| 3300 DartType returnType = functionNode.returnType.type; | 4586 DartType returnType = functionNode.returnType.type; |
| 3301 List<FormalParameter> parameters = | 4587 List<FormalParameter> parameters = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3321 } | 4607 } |
| 3322 | 4608 |
| 3323 test_perform_typedef() { | 4609 test_perform_typedef() { |
| 3324 Source source = newSource( | 4610 Source source = newSource( |
| 3325 '/test.dart', | 4611 '/test.dart', |
| 3326 ''' | 4612 ''' |
| 3327 typedef int F(G g); | 4613 typedef int F(G g); |
| 3328 typedef String G(int p); | 4614 typedef String G(int p); |
| 3329 '''); | 4615 '''); |
| 3330 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4616 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3331 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); | 4617 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); |
| 3332 // validate | 4618 // validate |
| 3333 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 4619 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 3334 FunctionTypeAlias nodeF = unit.declarations[0]; | 4620 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 3335 FunctionTypeAlias nodeG = unit.declarations[1]; | 4621 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 3336 { | 4622 { |
| 3337 FormalParameter parameter = nodeF.parameters.parameters[0]; | 4623 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 3338 DartType parameterType = parameter.element.type; | 4624 DartType parameterType = parameter.element.type; |
| 3339 Element returnTypeElement = nodeF.returnType.type.element; | 4625 Element returnTypeElement = nodeF.returnType.type.element; |
| 3340 expect(returnTypeElement.displayName, 'int'); | 4626 expect(returnTypeElement.displayName, 'int'); |
| 3341 expect(parameterType.element, nodeG.element); | 4627 expect(parameterType.element, nodeG.element); |
| 3342 } | 4628 } |
| 3343 { | 4629 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3363 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 4649 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 3364 } | 4650 } |
| 3365 } | 4651 } |
| 3366 | 4652 |
| 3367 @reflectiveTest | 4653 @reflectiveTest |
| 3368 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 4654 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 3369 /** | 4655 /** |
| 3370 * Verify that the mutated states of the given [variable] correspond to the | 4656 * Verify that the mutated states of the given [variable] correspond to the |
| 3371 * [mutatedInClosure] and [mutatedInScope] matchers. | 4657 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 3372 */ | 4658 */ |
| 3373 void expectMutated(VariableElement variable, Matcher mutatedInClosure, | 4659 void expectMutated(FunctionBody body, VariableElement variable, |
| 3374 Matcher mutatedInScope) { | 4660 bool mutatedInClosure, bool mutatedInScope) { |
| 3375 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); | 4661 expect(body.isPotentiallyMutatedInClosure(variable), mutatedInClosure); |
| 3376 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); | 4662 expect(body.isPotentiallyMutatedInScope(variable), mutatedInScope); |
| 4663 } |
| 4664 |
| 4665 test_created_resolved_unit() { |
| 4666 Source source = newSource( |
| 4667 '/test.dart', |
| 4668 r''' |
| 4669 library lib; |
| 4670 class A {} |
| 4671 '''); |
| 4672 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4673 computeResult(target, RESOLVED_UNIT6); |
| 4674 expect(outputs[RESOLVED_UNIT6], isNotNull); |
| 4675 expect(outputs[CREATED_RESOLVED_UNIT6], isTrue); |
| 3377 } | 4676 } |
| 3378 | 4677 |
| 3379 test_perform_buildClosureLibraryElements() { | 4678 test_perform_buildClosureLibraryElements() { |
| 3380 Source source = newSource( | 4679 Source source = newSource( |
| 3381 '/test.dart', | 4680 '/test.dart', |
| 3382 ''' | 4681 ''' |
| 3383 main() { | 4682 main() { |
| 3384 } | 4683 } |
| 3385 '''); | 4684 '''); |
| 3386 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4685 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3387 computeResult(target, RESOLVED_UNIT4, | 4686 computeResult(target, RESOLVED_UNIT6, |
| 3388 matcher: isResolveVariableReferencesTask); | 4687 matcher: isResolveVariableReferencesTask); |
| 3389 } | 4688 } |
| 3390 | 4689 |
| 3391 test_perform_local() { | 4690 test_perform_local() { |
| 3392 Source source = newSource( | 4691 Source source = newSource( |
| 3393 '/test.dart', | 4692 '/test.dart', |
| 3394 ''' | 4693 ''' |
| 3395 main() { | 4694 main() { |
| 3396 var v1 = 1; | 4695 var v1 = 1; |
| 3397 var v2 = 1; | 4696 var v2 = 1; |
| 3398 var v3 = 1; | 4697 var v3 = 1; |
| 3399 var v4 = 1; | 4698 var v4 = 1; |
| 3400 v2 = 2; | 4699 v2 = 2; |
| 3401 v4 = 2; | 4700 v4 = 2; |
| 3402 localFunction() { | 4701 localFunction() { |
| 3403 v3 = 3; | 4702 v3 = 3; |
| 3404 v4 = 3; | 4703 v4 = 3; |
| 3405 } | 4704 } |
| 3406 } | 4705 } |
| 3407 '''); | 4706 '''); |
| 3408 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4707 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3409 computeResult(target, RESOLVED_UNIT4, | 4708 computeResult(target, RESOLVED_UNIT6, |
| 3410 matcher: isResolveVariableReferencesTask); | 4709 matcher: isResolveVariableReferencesTask); |
| 3411 // validate | 4710 // validate |
| 3412 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 4711 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
| 3413 FunctionElement main = unit.element.functions[0]; | 4712 FunctionDeclaration mainDeclaration = unit.declarations[0]; |
| 3414 expectMutated(main.localVariables[0], isFalse, isFalse); | 4713 FunctionBody body = mainDeclaration.functionExpression.body; |
| 3415 expectMutated(main.localVariables[1], isFalse, isTrue); | 4714 FunctionElement main = mainDeclaration.element; |
| 3416 expectMutated(main.localVariables[2], isTrue, isTrue); | 4715 expectMutated(body, main.localVariables[0], false, false); |
| 3417 expectMutated(main.localVariables[3], isTrue, isTrue); | 4716 expectMutated(body, main.localVariables[1], false, true); |
| 4717 expectMutated(body, main.localVariables[2], true, true); |
| 4718 expectMutated(body, main.localVariables[3], true, true); |
| 3418 } | 4719 } |
| 3419 | 4720 |
| 3420 test_perform_parameter() { | 4721 test_perform_parameter() { |
| 3421 Source source = newSource( | 4722 Source source = newSource( |
| 3422 '/test.dart', | 4723 '/test.dart', |
| 3423 ''' | 4724 ''' |
| 3424 main(p1, p2, p3, p4) { | 4725 main(p1, p2, p3, p4) { |
| 3425 p2 = 2; | 4726 p2 = 2; |
| 3426 p4 = 2; | 4727 p4 = 2; |
| 3427 localFunction() { | 4728 localFunction() { |
| 3428 p3 = 3; | 4729 p3 = 3; |
| 3429 p4 = 3; | 4730 p4 = 3; |
| 3430 } | 4731 } |
| 3431 } | 4732 } |
| 3432 '''); | 4733 '''); |
| 3433 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4734 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3434 computeResult(target, RESOLVED_UNIT4, | 4735 computeResult(target, RESOLVED_UNIT6, |
| 3435 matcher: isResolveVariableReferencesTask); | 4736 matcher: isResolveVariableReferencesTask); |
| 3436 // validate | 4737 // validate |
| 3437 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 4738 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
| 3438 FunctionElement main = unit.element.functions[0]; | 4739 FunctionDeclaration mainDeclaration = unit.declarations[0]; |
| 3439 expectMutated(main.parameters[0], isFalse, isFalse); | 4740 FunctionBody body = mainDeclaration.functionExpression.body; |
| 3440 expectMutated(main.parameters[1], isFalse, isTrue); | 4741 FunctionElement main = mainDeclaration.element; |
| 3441 expectMutated(main.parameters[2], isTrue, isTrue); | 4742 expectMutated(body, main.parameters[0], false, false); |
| 3442 expectMutated(main.parameters[3], isTrue, isTrue); | 4743 expectMutated(body, main.parameters[1], false, true); |
| 4744 expectMutated(body, main.parameters[2], true, true); |
| 4745 expectMutated(body, main.parameters[3], true, true); |
| 3443 } | 4746 } |
| 3444 } | 4747 } |
| 3445 | 4748 |
| 3446 @reflectiveTest | 4749 @reflectiveTest |
| 3447 class ScanDartTaskTest extends _AbstractDartTaskTest { | 4750 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 4751 test_ignore_info() { |
| 4752 _performScanTask(''' |
| 4753 //ignore: error_code |
| 4754 var x = ''; |
| 4755 foo(); // ignore: error_code_2 |
| 4756 bar(); //ignore: error_code, error_code_2 |
| 4757 '''); |
| 4758 |
| 4759 IgnoreInfo info = outputs[IGNORE_INFO]; |
| 4760 expect(info.ignores.keys, hasLength(3)); |
| 4761 expect(info.ignores[1].first, 'error_code'); |
| 4762 expect(info.ignores[3].first, 'error_code_2'); |
| 4763 expect(info.ignores[4], unorderedEquals(['error_code', 'error_code_2'])); |
| 4764 } |
| 4765 |
| 3448 test_perform_errors() { | 4766 test_perform_errors() { |
| 3449 _performScanTask('import "'); | 4767 _performScanTask('import "'); |
| 3450 expect(outputs, hasLength(3)); | 4768 expect(outputs, hasLength(4)); |
| 3451 expect(outputs[LINE_INFO], isNotNull); | 4769 expect(outputs[LINE_INFO], isNotNull); |
| 3452 expect(outputs[SCAN_ERRORS], hasLength(1)); | 4770 expect(outputs[SCAN_ERRORS], hasLength(1)); |
| 3453 expect(outputs[TOKEN_STREAM], isNotNull); | 4771 expect(outputs[TOKEN_STREAM], isNotNull); |
| 4772 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; |
| 4773 expect(ignoreInfo, isNotNull); |
| 4774 expect(ignoreInfo.hasIgnores, isFalse); |
| 3454 } | 4775 } |
| 3455 | 4776 |
| 3456 test_perform_noErrors() { | 4777 test_perform_noErrors() { |
| 3457 _performScanTask('class A {}'); | 4778 _performScanTask('class A {}'); |
| 3458 expect(outputs, hasLength(3)); | 4779 expect(outputs, hasLength(4)); |
| 3459 expect(outputs[LINE_INFO], isNotNull); | 4780 expect(outputs[LINE_INFO], isNotNull); |
| 3460 expect(outputs[SCAN_ERRORS], hasLength(0)); | 4781 expect(outputs[SCAN_ERRORS], hasLength(0)); |
| 3461 expect(outputs[TOKEN_STREAM], isNotNull); | 4782 expect(outputs[TOKEN_STREAM], isNotNull); |
| 4783 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; |
| 4784 expect(ignoreInfo, isNotNull); |
| 4785 expect(ignoreInfo.hasIgnores, isFalse); |
| 3462 } | 4786 } |
| 3463 | 4787 |
| 3464 test_perform_script() { | 4788 test_perform_script() { |
| 3465 String scriptContent = ''' | 4789 String scriptContent = ''' |
| 3466 void buttonPressed() { | 4790 void buttonPressed() { |
| 3467 '''; | 4791 '''; |
| 3468 String htmlContent = ''' | 4792 String htmlContent = ''' |
| 3469 <!DOCTYPE html> | 4793 <!DOCTYPE html> |
| 3470 <html> | 4794 <html> |
| 3471 <head> | 4795 <head> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3504 // Check that even within a static variable cycle, inferred | 4828 // Check that even within a static variable cycle, inferred |
| 3505 // types get propagated to the members of the cycle. | 4829 // types get propagated to the members of the cycle. |
| 3506 void test_perform_cycle() { | 4830 void test_perform_cycle() { |
| 3507 AnalysisTarget source = newSource( | 4831 AnalysisTarget source = newSource( |
| 3508 '/test.dart', | 4832 '/test.dart', |
| 3509 ''' | 4833 ''' |
| 3510 var piFirst = true; | 4834 var piFirst = true; |
| 3511 var pi = piFirst ? 3.14 : tau / 2; | 4835 var pi = piFirst ? 3.14 : tau / 2; |
| 3512 var tau = piFirst ? pi * 2 : 6.28; | 4836 var tau = piFirst ? pi * 2 : 6.28; |
| 3513 '''); | 4837 '''); |
| 3514 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 4838 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3515 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 4839 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3516 VariableElement piFirst = | 4840 VariableElement piFirst = |
| 3517 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 4841 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 3518 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 4842 VariableElement pi = |
| 3519 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 4843 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 3520 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer | 4844 VariableElement tau = |
| 3521 as ConditionalExpression).condition; | 4845 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 4846 Expression piFirstUse = (AstFinder |
| 4847 .getTopLevelVariable(unit, 'tau') |
| 4848 .initializer as ConditionalExpression) |
| 4849 .condition; |
| 3522 | 4850 |
| 3523 expect(piFirstUse.staticType, context.typeProvider.boolType); | 4851 expect(piFirstUse.staticType, context.typeProvider.boolType); |
| 3524 expect(piFirst.type, context.typeProvider.boolType); | 4852 expect(piFirst.type, context.typeProvider.boolType); |
| 3525 expect(pi.type.isDynamic, isTrue); | 4853 expect(pi.type.isDynamic, isTrue); |
| 3526 expect(tau.type.isDynamic, isTrue); | 4854 expect(tau.type.isDynamic, isTrue); |
| 3527 } | 4855 } |
| 3528 | 4856 |
| 3529 void test_perform_inference_cross_unit_cyclic() { | 4857 void test_perform_inference_cross_unit_cyclic() { |
| 3530 AnalysisTarget firstSource = newSource( | 4858 AnalysisTarget firstSource = newSource( |
| 3531 '/a.dart', | 4859 '/a.dart', |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3543 | 4871 |
| 3544 test1() { | 4872 test1() { |
| 3545 int t = 3; | 4873 int t = 3; |
| 3546 t = x; | 4874 t = x; |
| 3547 t = y; | 4875 t = y; |
| 3548 t = A.x; | 4876 t = A.x; |
| 3549 t = B.y; | 4877 t = B.y; |
| 3550 } | 4878 } |
| 3551 '''); | 4879 '''); |
| 3552 computeResult( | 4880 computeResult( |
| 3553 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); | 4881 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11); |
| 3554 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; | 4882 CompilationUnit unit1 = outputs[RESOLVED_UNIT11]; |
| 3555 computeResult( | 4883 computeResult( |
| 3556 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); | 4884 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11); |
| 3557 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; | 4885 CompilationUnit unit2 = outputs[RESOLVED_UNIT11]; |
| 3558 | 4886 |
| 3559 InterfaceType intType = context.typeProvider.intType; | 4887 InterfaceType intType = context.typeProvider.intType; |
| 3560 | 4888 |
| 3561 assertVariableDeclarationTypes( | 4889 assertVariableDeclarationTypes( |
| 3562 getTopLevelVariable(unit1, "x"), intType, intType); | 4890 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); |
| 3563 assertVariableDeclarationTypes( | 4891 assertVariableDeclarationTypes( |
| 3564 getFieldInClass(unit1, "A", "x"), intType, intType); | 4892 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); |
| 3565 | 4893 |
| 3566 assertVariableDeclarationTypes( | 4894 assertVariableDeclarationTypes( |
| 3567 getTopLevelVariable(unit2, "y"), intType, intType); | 4895 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType); |
| 3568 assertVariableDeclarationTypes( | 4896 assertVariableDeclarationTypes( |
| 3569 getFieldInClass(unit2, "B", "y"), intType, intType); | 4897 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType); |
| 3570 | 4898 |
| 3571 List<Statement> statements = | 4899 List<Statement> statements = |
| 3572 getStatementsInTopLevelFunction(unit2, "test1"); | 4900 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3573 | 4901 |
| 3574 assertAssignmentStatementTypes(statements[1], intType, intType); | 4902 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3575 assertAssignmentStatementTypes(statements[2], intType, intType); | 4903 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3576 assertAssignmentStatementTypes(statements[3], intType, intType); | 4904 assertAssignmentStatementTypes(statements[3], intType, intType); |
| 3577 assertAssignmentStatementTypes(statements[4], intType, intType); | 4905 assertAssignmentStatementTypes(statements[4], intType, intType); |
| 3578 } | 4906 } |
| 3579 | 4907 |
| 3580 // Test that local variables in method bodies are inferred appropriately | 4908 // Test that local variables in method bodies are inferred appropriately |
| 3581 void test_perform_inference_cross_unit_instance() { | 4909 void test_perform_inference_cross_unit_instance() { |
| 3582 List<Source> sources = newSources({ | 4910 List<Source> sources = newSources({ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3594 '/main.dart': ''' | 4922 '/main.dart': ''' |
| 3595 import "a.dart"; | 4923 import "a.dart"; |
| 3596 | 4924 |
| 3597 test1() { | 4925 test1() { |
| 3598 int x = 0; | 4926 int x = 0; |
| 3599 x = new A().a2; | 4927 x = new A().a2; |
| 3600 } | 4928 } |
| 3601 ''' | 4929 ''' |
| 3602 }); | 4930 }); |
| 3603 List<dynamic> units = | 4931 List<dynamic> units = |
| 3604 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); | 4932 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
| 3605 CompilationUnit unit0 = units[0]; | 4933 CompilationUnit unit0 = units[0]; |
| 3606 CompilationUnit unit1 = units[1]; | 4934 CompilationUnit unit1 = units[1]; |
| 3607 CompilationUnit unit2 = units[2]; | 4935 CompilationUnit unit2 = units[2]; |
| 3608 | 4936 |
| 3609 InterfaceType intType = context.typeProvider.intType; | 4937 InterfaceType intType = context.typeProvider.intType; |
| 3610 | 4938 |
| 3611 assertVariableDeclarationTypes( | 4939 assertVariableDeclarationTypes( |
| 3612 getFieldInClass(unit0, "A", "a2"), intType, intType); | 4940 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3613 | 4941 |
| 3614 assertVariableDeclarationTypes( | 4942 assertVariableDeclarationTypes( |
| 3615 getFieldInClass(unit1, "B", "b2"), intType, intType); | 4943 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3616 | 4944 |
| 3617 List<Statement> statements = | 4945 List<Statement> statements = |
| 3618 getStatementsInTopLevelFunction(unit2, "test1"); | 4946 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3619 | 4947 |
| 3620 assertAssignmentStatementTypes(statements[1], intType, intType); | 4948 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3621 } | 4949 } |
| 3622 | 4950 |
| 3623 // Test inference interactions between local variables and fields | 4951 // Test inference interactions between local variables and fields |
| 3624 void test_perform_inference_cross_unit_instance_member() { | 4952 void test_perform_inference_cross_unit_instance_member() { |
| 3625 List<Source> sources = newSources({ | 4953 List<Source> sources = newSources({ |
| 3626 '/a.dart': ''' | 4954 '/a.dart': ''' |
| 3627 import 'b.dart'; | 4955 import 'b.dart'; |
| 3628 var bar = new B(); | 4956 var bar = new B(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3641 ''', | 4969 ''', |
| 3642 '/c.dart': ''' | 4970 '/c.dart': ''' |
| 3643 import 'b.dart'; | 4971 import 'b.dart'; |
| 3644 var bar = new B(); | 4972 var bar = new B(); |
| 3645 void foo() { | 4973 void foo() { |
| 3646 String x = bar.f.z; | 4974 String x = bar.f.z; |
| 3647 } | 4975 } |
| 3648 ''' | 4976 ''' |
| 3649 }); | 4977 }); |
| 3650 List<dynamic> units = | 4978 List<dynamic> units = |
| 3651 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); | 4979 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
| 3652 CompilationUnit unit0 = units[0]; | 4980 CompilationUnit unit0 = units[0]; |
| 3653 CompilationUnit unit1 = units[1]; | |
| 3654 CompilationUnit unit2 = units[2]; | 4981 CompilationUnit unit2 = units[2]; |
| 3655 | 4982 |
| 3656 InterfaceType intType = context.typeProvider.intType; | 4983 InterfaceType intType = context.typeProvider.intType; |
| 3657 InterfaceType stringType = context.typeProvider.stringType; | 4984 InterfaceType stringType = context.typeProvider.stringType; |
| 3658 | 4985 |
| 3659 assertVariableDeclarationStatementTypes( | 4986 assertVariableDeclarationStatementTypes( |
| 3660 getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType); | 4987 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0], |
| 4988 stringType, |
| 4989 intType); |
| 3661 assertVariableDeclarationStatementTypes( | 4990 assertVariableDeclarationStatementTypes( |
| 3662 getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType); | 4991 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], |
| 4992 stringType, |
| 4993 intType); |
| 3663 } | 4994 } |
| 3664 | 4995 |
| 3665 // Test inference interactions between local variables and top level | 4996 // Test inference interactions between local variables and top level |
| 3666 // variables | 4997 // variables |
| 3667 void test_perform_inference_cross_unit_non_cyclic() { | 4998 void test_perform_inference_cross_unit_non_cyclic() { |
| 3668 AnalysisTarget firstSource = newSource( | 4999 AnalysisTarget firstSource = newSource( |
| 3669 '/a.dart', | 5000 '/a.dart', |
| 3670 ''' | 5001 ''' |
| 3671 var x = 2; | 5002 var x = 2; |
| 3672 class A { static var x = 2; } | 5003 class A { static var x = 2; } |
| 3673 '''); | 5004 '''); |
| 3674 AnalysisTarget secondSource = newSource( | 5005 AnalysisTarget secondSource = newSource( |
| 3675 '/test.dart', | 5006 '/test.dart', |
| 3676 ''' | 5007 ''' |
| 3677 import 'a.dart'; | 5008 import 'a.dart'; |
| 3678 var y = x; | 5009 var y = x; |
| 3679 class B { static var y = A.x; } | 5010 class B { static var y = A.x; } |
| 3680 | 5011 |
| 3681 test1() { | 5012 test1() { |
| 3682 x = /*severe:StaticTypeError*/"hi"; | 5013 x = /*severe:StaticTypeError*/"hi"; |
| 3683 y = /*severe:StaticTypeError*/"hi"; | 5014 y = /*severe:StaticTypeError*/"hi"; |
| 3684 A.x = /*severe:StaticTypeError*/"hi"; | 5015 A.x = /*severe:StaticTypeError*/"hi"; |
| 3685 B.y = /*severe:StaticTypeError*/"hi"; | 5016 B.y = /*severe:StaticTypeError*/"hi"; |
| 3686 } | 5017 } |
| 3687 '''); | 5018 '''); |
| 3688 computeResult( | 5019 computeResult( |
| 3689 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); | 5020 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11); |
| 3690 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; | 5021 CompilationUnit unit1 = outputs[RESOLVED_UNIT11]; |
| 3691 computeResult( | 5022 computeResult( |
| 3692 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); | 5023 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11); |
| 3693 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; | 5024 CompilationUnit unit2 = outputs[RESOLVED_UNIT11]; |
| 3694 | 5025 |
| 3695 InterfaceType intType = context.typeProvider.intType; | 5026 InterfaceType intType = context.typeProvider.intType; |
| 3696 InterfaceType stringType = context.typeProvider.stringType; | 5027 InterfaceType stringType = context.typeProvider.stringType; |
| 3697 | 5028 |
| 3698 assertVariableDeclarationTypes( | 5029 assertVariableDeclarationTypes( |
| 3699 getTopLevelVariable(unit1, "x"), intType, intType); | 5030 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); |
| 3700 assertVariableDeclarationTypes( | 5031 assertVariableDeclarationTypes( |
| 3701 getFieldInClass(unit1, "A", "x"), intType, intType); | 5032 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); |
| 3702 | 5033 |
| 3703 assertVariableDeclarationTypes( | 5034 assertVariableDeclarationTypes( |
| 3704 getTopLevelVariable(unit2, "y"), intType, intType); | 5035 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType); |
| 3705 assertVariableDeclarationTypes( | 5036 assertVariableDeclarationTypes( |
| 3706 getFieldInClass(unit2, "B", "y"), intType, intType); | 5037 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType); |
| 3707 | 5038 |
| 3708 List<Statement> statements = | 5039 List<Statement> statements = |
| 3709 getStatementsInTopLevelFunction(unit2, "test1"); | 5040 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3710 | 5041 |
| 3711 assertAssignmentStatementTypes(statements[0], intType, stringType); | 5042 assertAssignmentStatementTypes(statements[0], intType, stringType); |
| 3712 assertAssignmentStatementTypes(statements[1], intType, stringType); | 5043 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3713 } | 5044 } |
| 3714 | 5045 |
| 3715 // Test that inference does not propagate from null | 5046 // Test that inference does not propagate from null |
| 3716 void test_perform_inference_cross_unit_static_instance() { | 5047 void test_perform_inference_cross_unit_static_instance() { |
| 3717 List<Source> sources = newSources({ | 5048 List<Source> sources = newSources({ |
| 3718 '/a.dart': ''' | 5049 '/a.dart': ''' |
| 3719 import 'b.dart'; | 5050 import 'b.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3733 | 5064 |
| 3734 test1() { | 5065 test1() { |
| 3735 int x = 0; | 5066 int x = 0; |
| 3736 // inference in A now works. | 5067 // inference in A now works. |
| 3737 x = A.a1; | 5068 x = A.a1; |
| 3738 x = new A().a2; | 5069 x = new A().a2; |
| 3739 } | 5070 } |
| 3740 ''' | 5071 ''' |
| 3741 }); | 5072 }); |
| 3742 List<dynamic> units = | 5073 List<dynamic> units = |
| 3743 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); | 5074 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
| 3744 CompilationUnit unit0 = units[0]; | 5075 CompilationUnit unit0 = units[0]; |
| 3745 CompilationUnit unit1 = units[1]; | 5076 CompilationUnit unit1 = units[1]; |
| 3746 CompilationUnit unit2 = units[2]; | 5077 CompilationUnit unit2 = units[2]; |
| 3747 | 5078 |
| 3748 InterfaceType intType = context.typeProvider.intType; | 5079 InterfaceType intType = context.typeProvider.intType; |
| 3749 | 5080 |
| 3750 assertVariableDeclarationTypes( | 5081 assertVariableDeclarationTypes( |
| 3751 getFieldInClass(unit0, "A", "a1"), intType, intType); | 5082 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
| 3752 assertVariableDeclarationTypes( | 5083 assertVariableDeclarationTypes( |
| 3753 getFieldInClass(unit0, "A", "a2"), intType, intType); | 5084 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
| 3754 | 5085 |
| 3755 assertVariableDeclarationTypes( | 5086 assertVariableDeclarationTypes( |
| 3756 getFieldInClass(unit1, "B", "b1"), intType, intType); | 5087 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
| 3757 assertVariableDeclarationTypes( | 5088 assertVariableDeclarationTypes( |
| 3758 getFieldInClass(unit1, "B", "b2"), intType, intType); | 5089 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
| 3759 | 5090 |
| 3760 List<Statement> statements = | 5091 List<Statement> statements = |
| 3761 getStatementsInTopLevelFunction(unit2, "test1"); | 5092 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 3762 | 5093 |
| 3763 assertAssignmentStatementTypes(statements[1], intType, intType); | 5094 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3764 assertAssignmentStatementTypes(statements[2], intType, intType); | 5095 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3765 } | 5096 } |
| 3766 | 5097 |
| 3767 // Test inference across units (non-cyclic) | 5098 // Test inference across units (non-cyclic) |
| 3768 void test_perform_inference_local_variables() { | 5099 void test_perform_inference_local_variables() { |
| 3769 AnalysisTarget source = newSource( | 5100 AnalysisTarget source = newSource( |
| 3770 '/test.dart', | 5101 '/test.dart', |
| 3771 ''' | 5102 ''' |
| 3772 test() { | 5103 test() { |
| 3773 int x = 3; | 5104 int x = 3; |
| 3774 x = "hi"; | 5105 x = "hi"; |
| 3775 var y = 3; | 5106 var y = 3; |
| 3776 y = "hi"; | 5107 y = "hi"; |
| 3777 } | 5108 } |
| 3778 '''); | 5109 '''); |
| 3779 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 5110 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3780 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 5111 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3781 | 5112 |
| 3782 InterfaceType intType = context.typeProvider.intType; | 5113 InterfaceType intType = context.typeProvider.intType; |
| 3783 InterfaceType stringType = context.typeProvider.stringType; | 5114 InterfaceType stringType = context.typeProvider.stringType; |
| 3784 | 5115 |
| 3785 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 5116 List<Statement> statements = |
| 5117 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 3786 | 5118 |
| 3787 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 5119 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 3788 assertAssignmentStatementTypes(statements[1], intType, stringType); | 5120 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3789 assertVariableDeclarationStatementTypes(statements[2], intType, intType); | 5121 assertVariableDeclarationStatementTypes(statements[2], intType, intType); |
| 3790 assertAssignmentStatementTypes(statements[3], intType, stringType); | 5122 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 3791 } | 5123 } |
| 3792 | 5124 |
| 3793 // Test inference across units (cyclic) | 5125 // Test inference across units (cyclic) |
| 3794 void test_perform_inference_local_variables_fields() { | 5126 void test_perform_inference_local_variables_fields() { |
| 3795 AnalysisTarget source = newSource( | 5127 AnalysisTarget source = newSource( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3807 b = 4; | 5139 b = 4; |
| 3808 var c = z; | 5140 var c = z; |
| 3809 c = "hi"; | 5141 c = "hi"; |
| 3810 c = 4; | 5142 c = 4; |
| 3811 } | 5143 } |
| 3812 | 5144 |
| 3813 int y; // field def after use | 5145 int y; // field def after use |
| 3814 final z = 42; // should infer `int` | 5146 final z = 42; // should infer `int` |
| 3815 } | 5147 } |
| 3816 '''); | 5148 '''); |
| 3817 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 5149 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3818 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 5150 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3819 | 5151 |
| 3820 InterfaceType intType = context.typeProvider.intType; | 5152 InterfaceType intType = context.typeProvider.intType; |
| 3821 InterfaceType stringType = context.typeProvider.stringType; | 5153 InterfaceType stringType = context.typeProvider.stringType; |
| 3822 | 5154 |
| 3823 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); | 5155 List<Statement> statements = |
| 5156 AstFinder.getStatementsInMethod(unit, "A", "test1"); |
| 3824 | 5157 |
| 3825 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 5158 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 3826 assertAssignmentStatementTypes(statements[1], intType, stringType); | 5159 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3827 assertAssignmentStatementTypes(statements[2], intType, intType); | 5160 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3828 | 5161 |
| 3829 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 5162 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
| 3830 assertAssignmentStatementTypes(statements[4], intType, stringType); | 5163 assertAssignmentStatementTypes(statements[4], intType, stringType); |
| 3831 assertAssignmentStatementTypes(statements[5], intType, intType); | 5164 assertAssignmentStatementTypes(statements[5], intType, intType); |
| 3832 | 5165 |
| 3833 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 5166 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
| 3834 assertAssignmentStatementTypes(statements[7], intType, stringType); | 5167 assertAssignmentStatementTypes(statements[7], intType, stringType); |
| 3835 assertAssignmentStatementTypes(statements[8], intType, intType); | 5168 assertAssignmentStatementTypes(statements[8], intType, intType); |
| 3836 | 5169 |
| 3837 assertVariableDeclarationTypes( | 5170 assertVariableDeclarationTypes( |
| 3838 getFieldInClass(unit, "A", "x"), intType, intType); | 5171 AstFinder.getFieldInClass(unit, "A", "x"), intType, intType); |
| 3839 assertVariableDeclarationTypes( | 5172 assertVariableDeclarationTypes( |
| 3840 getFieldInClass(unit, "A", "z"), intType, intType); | 5173 AstFinder.getFieldInClass(unit, "A", "z"), intType, intType); |
| 3841 } | 5174 } |
| 3842 | 5175 |
| 3843 // Test inference of instance fields across units | 5176 // Test inference of instance fields across units |
| 3844 void test_perform_inference_local_variables_topLevel() { | 5177 void test_perform_inference_local_variables_topLevel() { |
| 3845 AnalysisTarget source = newSource( | 5178 AnalysisTarget source = newSource( |
| 3846 '/test.dart', | 5179 '/test.dart', |
| 3847 ''' | 5180 ''' |
| 3848 int x = 0; | 5181 int x = 0; |
| 3849 | 5182 |
| 3850 test1() { | 5183 test1() { |
| 3851 var a = x; | 5184 var a = x; |
| 3852 a = /*severe:StaticTypeError*/"hi"; | 5185 a = /*severe:StaticTypeError*/"hi"; |
| 3853 a = 3; | 5186 a = 3; |
| 3854 var b = y; | 5187 var b = y; |
| 3855 b = /*severe:StaticTypeError*/"hi"; | 5188 b = /*severe:StaticTypeError*/"hi"; |
| 3856 b = 4; | 5189 b = 4; |
| 3857 var c = z; | 5190 var c = z; |
| 3858 c = /*severe:StaticTypeError*/"hi"; | 5191 c = /*severe:StaticTypeError*/"hi"; |
| 3859 c = 4; | 5192 c = 4; |
| 3860 } | 5193 } |
| 3861 | 5194 |
| 3862 int y = 0; // field def after use | 5195 int y = 0; // field def after use |
| 3863 final z = 42; // should infer `int` | 5196 final z = 42; // should infer `int` |
| 3864 '''); | 5197 '''); |
| 3865 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 5198 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3866 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 5199 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3867 | 5200 |
| 3868 InterfaceType intType = context.typeProvider.intType; | 5201 InterfaceType intType = context.typeProvider.intType; |
| 3869 InterfaceType stringType = context.typeProvider.stringType; | 5202 InterfaceType stringType = context.typeProvider.stringType; |
| 3870 | 5203 |
| 3871 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); | 5204 List<Statement> statements = |
| 5205 AstFinder.getStatementsInTopLevelFunction(unit, "test1"); |
| 3872 | 5206 |
| 3873 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 5207 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 3874 assertAssignmentStatementTypes(statements[1], intType, stringType); | 5208 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3875 assertAssignmentStatementTypes(statements[2], intType, intType); | 5209 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 3876 | 5210 |
| 3877 assertVariableDeclarationStatementTypes(statements[3], intType, intType); | 5211 assertVariableDeclarationStatementTypes(statements[3], intType, intType); |
| 3878 assertAssignmentStatementTypes(statements[4], intType, stringType); | 5212 assertAssignmentStatementTypes(statements[4], intType, stringType); |
| 3879 assertAssignmentStatementTypes(statements[5], intType, intType); | 5213 assertAssignmentStatementTypes(statements[5], intType, intType); |
| 3880 | 5214 |
| 3881 assertVariableDeclarationStatementTypes(statements[6], intType, intType); | 5215 assertVariableDeclarationStatementTypes(statements[6], intType, intType); |
| 3882 assertAssignmentStatementTypes(statements[7], intType, stringType); | 5216 assertAssignmentStatementTypes(statements[7], intType, stringType); |
| 3883 assertAssignmentStatementTypes(statements[8], intType, intType); | 5217 assertAssignmentStatementTypes(statements[8], intType, intType); |
| 3884 | 5218 |
| 3885 assertVariableDeclarationTypes( | 5219 assertVariableDeclarationTypes( |
| 3886 getTopLevelVariable(unit, "x"), intType, intType); | 5220 AstFinder.getTopLevelVariable(unit, "x"), intType, intType); |
| 3887 assertVariableDeclarationTypes( | 5221 assertVariableDeclarationTypes( |
| 3888 getTopLevelVariable(unit, "y"), intType, intType); | 5222 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); |
| 3889 assertVariableDeclarationTypes( | 5223 assertVariableDeclarationTypes( |
| 3890 getTopLevelVariable(unit, "z"), intType, intType); | 5224 AstFinder.getTopLevelVariable(unit, "z"), intType, intType); |
| 3891 } | 5225 } |
| 3892 | 5226 |
| 3893 // Test inference between static and instance fields | 5227 // Test inference between static and instance fields |
| 3894 void test_perform_inference_null() { | 5228 void test_perform_inference_null() { |
| 3895 AnalysisTarget source = newSource( | 5229 AnalysisTarget source = newSource( |
| 3896 '/test.dart', | 5230 '/test.dart', |
| 3897 ''' | 5231 ''' |
| 3898 var x = null; | 5232 var x = null; |
| 3899 var y = 3; | 5233 var y = 3; |
| 3900 class A { | 5234 class A { |
| 3901 static var x = null; | 5235 static var x = null; |
| 3902 static var y = 3; | 5236 static var y = 3; |
| 3903 | 5237 |
| 3904 var x2 = null; | 5238 var x2 = null; |
| 3905 var y2 = 3; | 5239 var y2 = 3; |
| 3906 } | 5240 } |
| 3907 | 5241 |
| 3908 test() { | 5242 test() { |
| 3909 x = "hi"; | 5243 x = "hi"; |
| 3910 y = /*severe:StaticTypeError*/"hi"; | 5244 y = /*severe:StaticTypeError*/"hi"; |
| 3911 A.x = "hi"; | 5245 A.x = "hi"; |
| 3912 A.y = /*severe:StaticTypeError*/"hi"; | 5246 A.y = /*severe:StaticTypeError*/"hi"; |
| 3913 new A().x2 = "hi"; | 5247 new A().x2 = "hi"; |
| 3914 new A().y2 = /*severe:StaticTypeError*/"hi"; | 5248 new A().y2 = /*severe:StaticTypeError*/"hi"; |
| 3915 } | 5249 } |
| 3916 '''); | 5250 '''); |
| 3917 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 5251 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3918 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 5252 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3919 | 5253 |
| 3920 InterfaceType intType = context.typeProvider.intType; | 5254 InterfaceType intType = context.typeProvider.intType; |
| 3921 InterfaceType stringType = context.typeProvider.stringType; | 5255 InterfaceType stringType = context.typeProvider.stringType; |
| 3922 DartType bottomType = context.typeProvider.bottomType; | 5256 DartType bottomType = context.typeProvider.bottomType; |
| 3923 DartType dynamicType = context.typeProvider.dynamicType; | 5257 DartType dynamicType = context.typeProvider.dynamicType; |
| 3924 | 5258 |
| 3925 assertVariableDeclarationTypes( | 5259 assertVariableDeclarationTypes( |
| 3926 getTopLevelVariable(unit, "x"), dynamicType, bottomType); | 5260 AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType); |
| 3927 assertVariableDeclarationTypes( | 5261 assertVariableDeclarationTypes( |
| 3928 getTopLevelVariable(unit, "y"), intType, intType); | 5262 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); |
| 3929 assertVariableDeclarationTypes( | 5263 assertVariableDeclarationTypes( |
| 3930 getFieldInClass(unit, "A", "x"), dynamicType, bottomType); | 5264 AstFinder.getFieldInClass(unit, "A", "x"), dynamicType, bottomType); |
| 3931 assertVariableDeclarationTypes( | 5265 assertVariableDeclarationTypes( |
| 3932 getFieldInClass(unit, "A", "y"), intType, intType); | 5266 AstFinder.getFieldInClass(unit, "A", "y"), intType, intType); |
| 3933 assertVariableDeclarationTypes( | 5267 assertVariableDeclarationTypes( |
| 3934 getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); | 5268 AstFinder.getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); |
| 3935 assertVariableDeclarationTypes( | 5269 assertVariableDeclarationTypes( |
| 3936 getFieldInClass(unit, "A", "y2"), intType, intType); | 5270 AstFinder.getFieldInClass(unit, "A", "y2"), intType, intType); |
| 3937 | 5271 |
| 3938 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 5272 List<Statement> statements = |
| 5273 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 3939 | 5274 |
| 3940 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); | 5275 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); |
| 3941 assertAssignmentStatementTypes(statements[1], intType, stringType); | 5276 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 3942 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); | 5277 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); |
| 3943 assertAssignmentStatementTypes(statements[3], intType, stringType); | 5278 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 3944 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); | 5279 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); |
| 3945 assertAssignmentStatementTypes(statements[5], intType, stringType); | 5280 assertAssignmentStatementTypes(statements[5], intType, stringType); |
| 3946 } | 5281 } |
| 3947 | 5282 |
| 3948 // Test inference between fields and method bodies | 5283 // Test inference between fields and method bodies |
| 3949 void test_perform_local_explicit_disabled() { | 5284 void test_perform_local_explicit_disabled() { |
| 3950 AnalysisTarget source = newSource( | 5285 AnalysisTarget source = newSource( |
| 3951 '/test.dart', | 5286 '/test.dart', |
| 3952 ''' | 5287 ''' |
| 3953 test() { | 5288 test() { |
| 3954 int x = 3; | 5289 int x = 3; |
| 3955 x = "hi"; | 5290 x = "hi"; |
| 3956 } | 5291 } |
| 3957 '''); | 5292 '''); |
| 3958 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); | 5293 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 3959 CompilationUnit unit = outputs[RESOLVED_UNIT9]; | 5294 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 3960 | 5295 |
| 3961 InterfaceType intType = context.typeProvider.intType; | 5296 InterfaceType intType = context.typeProvider.intType; |
| 3962 InterfaceType stringType = context.typeProvider.stringType; | 5297 InterfaceType stringType = context.typeProvider.stringType; |
| 3963 | 5298 |
| 3964 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); | 5299 List<Statement> statements = |
| 5300 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 3965 VariableDeclaration decl = | 5301 VariableDeclaration decl = |
| 3966 (statements[0] as VariableDeclarationStatement).variables.variables[0]; | 5302 (statements[0] as VariableDeclarationStatement).variables.variables[0]; |
| 3967 expect(decl.element.type, intType); | 5303 expect(decl.element.type, intType); |
| 3968 expect(decl.initializer.staticType, intType); | 5304 expect(decl.initializer.staticType, intType); |
| 3969 | 5305 |
| 3970 ExpressionStatement statement = statements[1]; | 5306 ExpressionStatement statement = statements[1]; |
| 3971 AssignmentExpression assgn = statement.expression; | 5307 AssignmentExpression assgn = statement.expression; |
| 3972 expect(assgn.leftHandSide.staticType, intType); | 5308 expect(assgn.leftHandSide.staticType, intType); |
| 3973 expect(assgn.rightHandSide.staticType, stringType); | 5309 expect(assgn.rightHandSide.staticType, stringType); |
| 3974 } | 5310 } |
| 3975 } | 5311 } |
| 3976 | 5312 |
| 3977 @reflectiveTest | 5313 @reflectiveTest |
| 3978 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { | 5314 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 3979 @override | 5315 @override |
| 3980 void setUp() { | 5316 void setUp() { |
| 3981 super.setUp(); | 5317 super.setUp(); |
| 3982 enableStrongMode(); | 5318 enableStrongMode(); |
| 3983 } | 5319 } |
| 3984 | 5320 |
| 5321 test_created_resolved_unit() { |
| 5322 Source source = newSource( |
| 5323 '/test.dart', |
| 5324 r''' |
| 5325 library lib; |
| 5326 class A {} |
| 5327 '''); |
| 5328 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5329 computeResult(target, RESOLVED_UNIT); |
| 5330 expect(outputs[RESOLVED_UNIT], isNotNull); |
| 5331 expect(outputs[CREATED_RESOLVED_UNIT], isTrue); |
| 5332 } |
| 5333 |
| 3985 void test_perform_recordDynamicInvoke() { | 5334 void test_perform_recordDynamicInvoke() { |
| 3986 enableStrongMode(); | 5335 enableStrongMode(); |
| 3987 AnalysisTarget source = newSource( | 5336 AnalysisTarget source = newSource( |
| 3988 '/test.dart', | 5337 '/test.dart', |
| 3989 ''' | 5338 ''' |
| 3990 void main() { | 5339 void main() { |
| 3991 dynamic a = []; | 5340 dynamic a = []; |
| 3992 a[0]; | 5341 a[0]; |
| 3993 } | 5342 } |
| 3994 '''); | 5343 '''); |
| 3995 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); | 5344 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 3996 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 5345 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 3997 | 5346 |
| 3998 // validate | 5347 // validate |
| 3999 _fillErrorListener(STRONG_MODE_ERRORS); | 5348 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4000 expect(errorListener.errors, isEmpty); | 5349 expect(errorListener.errors, isEmpty); |
| 4001 | 5350 |
| 4002 List<Statement> statements = getStatementsInTopLevelFunction(unit, "main"); | 5351 List<Statement> statements = |
| 5352 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 4003 ExpressionStatement statement = statements[1]; | 5353 ExpressionStatement statement = statements[1]; |
| 4004 IndexExpression idx = statement.expression; | 5354 IndexExpression idx = statement.expression; |
| 4005 expect(DynamicInvoke.get(idx.target), isNotNull); | 5355 expect(strong_ast.isDynamicInvoke(idx.target), isTrue); |
| 4006 expect(DynamicInvoke.get(idx.target), isNotNull); | |
| 4007 expect(DynamicInvoke.get(idx.target), isTrue); | |
| 4008 } | 5356 } |
| 4009 | 5357 |
| 4010 void test_perform_verifyError() { | 5358 void test_perform_verifyError() { |
| 4011 enableStrongMode(); | 5359 enableStrongMode(); |
| 4012 AnalysisTarget source = newSource( | 5360 AnalysisTarget source = newSource( |
| 4013 '/test.dart', | 5361 '/test.dart', |
| 4014 ''' | 5362 ''' |
| 4015 int topLevel = 3; | 5363 class A {} |
| 4016 class C { | 5364 class B extends A {} |
| 4017 String field = topLevel; | 5365 B b = new A(); |
| 4018 } | |
| 4019 '''); | 5366 '''); |
| 4020 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); | 5367 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 4021 // validate | 5368 // validate |
| 4022 _fillErrorListener(STRONG_MODE_ERRORS); | 5369 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4023 | 5370 |
| 4024 var errors = errorListener.errors; | 5371 var errors = errorListener.errors; |
| 4025 expect(errors.length, 1); | 5372 expect(errors.length, 1); |
| 4026 expect(errors[0].errorCode.name, "dev_compiler.StaticTypeError"); | 5373 expect(errors[0].errorCode.name, "STRONG_MODE_STATIC_TYPE_ERROR"); |
| 4027 } | 5374 } |
| 4028 } | 5375 } |
| 4029 | 5376 |
| 4030 @reflectiveTest | 5377 @reflectiveTest |
| 4031 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 5378 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 4032 test_perform_constantError() { | 5379 test_perform_constantError() { |
| 4033 Source source = newSource( | 5380 Source source = newSource( |
| 4034 '/test.dart', | 5381 '/test.dart', |
| 4035 ''' | 5382 ''' |
| 4036 main(int p) { | 5383 main(int p) { |
| 4037 const v = p; | 5384 const v = p; |
| 4038 } | 5385 } |
| 4039 '''); | 5386 '''); |
| 4040 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 5387 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4041 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 5388 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4042 // validate | 5389 // validate |
| 4043 _fillErrorListener(VERIFY_ERRORS); | 5390 _fillErrorListener(VERIFY_ERRORS); |
| 4044 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 5391 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 4045 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 5392 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 4046 ]); | 5393 ]); |
| 4047 } | 5394 } |
| 4048 | 5395 |
| 4049 test_perform_directiveError() { | 5396 test_perform_ConstantValidator_declaredIdentifier() { |
| 4050 Source source = newSource( | 5397 Source source = newSource( |
| 4051 '/test.dart', | 5398 '/test.dart', |
| 4052 ''' | 5399 ''' |
| 5400 void main() { |
| 5401 for (const foo in []) { |
| 5402 print(foo); |
| 5403 } |
| 5404 } |
| 5405 '''); |
| 5406 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5407 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5408 // validate |
| 5409 _fillErrorListener(VERIFY_ERRORS); |
| 5410 errorListener.assertNoErrors(); |
| 5411 } |
| 5412 |
| 5413 test_perform_ConstantValidator_dependencyCycle() { |
| 5414 Source source = newSource( |
| 5415 '/test.dart', |
| 5416 ''' |
| 5417 const int a = b; |
| 5418 const int b = c; |
| 5419 const int c = a; |
| 5420 '''); |
| 5421 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5422 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5423 // validate |
| 5424 _fillErrorListener(VERIFY_ERRORS); |
| 5425 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 5426 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 5427 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 5428 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT |
| 5429 ]); |
| 5430 } |
| 5431 |
| 5432 test_perform_ConstantValidator_duplicateFields() { |
| 5433 Source source = newSource( |
| 5434 '/test.dart', |
| 5435 ''' |
| 5436 class Test { |
| 5437 final int x = 1; |
| 5438 final int x = 2; |
| 5439 const Test(); |
| 5440 } |
| 5441 |
| 5442 main() { |
| 5443 const Test(); |
| 5444 } |
| 5445 '''); |
| 5446 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5447 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5448 // validate |
| 5449 _fillErrorListener(VERIFY_ERRORS); |
| 5450 errorListener |
| 5451 .assertErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 5452 } |
| 5453 |
| 5454 test_perform_ConstantValidator_noInitializer() { |
| 5455 Source source = newSource( |
| 5456 '/test.dart', |
| 5457 ''' |
| 5458 const x; |
| 5459 '''); |
| 5460 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5461 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5462 // validate |
| 5463 _fillErrorListener(VERIFY_ERRORS); |
| 5464 errorListener.assertErrorsWithCodes( |
| 5465 <ErrorCode>[CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 5466 } |
| 5467 |
| 5468 test_perform_ConstantValidator_unknownValue() { |
| 5469 Source source = newSource( |
| 5470 '/test.dart', |
| 5471 ''' |
| 5472 import 'no-such-file.dart' as p; |
| 5473 |
| 5474 const int x = p.y; |
| 5475 '''); |
| 5476 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5477 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5478 // validate |
| 5479 _fillErrorListener(VERIFY_ERRORS); |
| 5480 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 5481 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 5482 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 5483 ]); |
| 5484 } |
| 5485 |
| 5486 test_perform_directiveError_generated() { |
| 5487 Source source = newSource( |
| 5488 '/test.dart', |
| 5489 ''' |
| 5490 import 'generated-file.g.dart'; |
| 5491 '''); |
| 5492 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5493 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5494 // validate |
| 5495 _fillErrorListener(VERIFY_ERRORS); |
| 5496 errorListener.assertErrorsWithCodes( |
| 5497 <ErrorCode>[CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED]); |
| 5498 } |
| 5499 |
| 5500 test_perform_directiveError_nonGenerated() { |
| 5501 Source source = newSource( |
| 5502 '/test.dart', |
| 5503 ''' |
| 4053 import 'no-such-file.dart'; | 5504 import 'no-such-file.dart'; |
| 4054 '''); | 5505 '''); |
| 4055 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 5506 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4056 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 5507 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4057 // validate | 5508 // validate |
| 4058 _fillErrorListener(VERIFY_ERRORS); | 5509 _fillErrorListener(VERIFY_ERRORS); |
| 4059 errorListener.assertErrorsWithCodes( | 5510 errorListener.assertErrorsWithCodes( |
| 4060 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 5511 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 4061 } | 5512 } |
| 4062 | 5513 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4142 } | 5593 } |
| 4143 | 5594 |
| 4144 List<dynamic> computeLibraryResults( | 5595 List<dynamic> computeLibraryResults( |
| 4145 List<Source> sources, ResultDescriptor result, | 5596 List<Source> sources, ResultDescriptor result, |
| 4146 {isInstanceOf matcher: null}) { | 5597 {isInstanceOf matcher: null}) { |
| 4147 dynamic compute(Source source) { | 5598 dynamic compute(Source source) { |
| 4148 computeResult(new LibrarySpecificUnit(source, source), result, | 5599 computeResult(new LibrarySpecificUnit(source, source), result, |
| 4149 matcher: matcher); | 5600 matcher: matcher); |
| 4150 return outputs[result]; | 5601 return outputs[result]; |
| 4151 } | 5602 } |
| 5603 |
| 4152 return sources.map(compute).toList(); | 5604 return sources.map(compute).toList(); |
| 4153 } | 5605 } |
| 4154 | 5606 |
| 4155 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( | 5607 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( |
| 4156 List<Source> sources, ResultDescriptor result, | 5608 List<Source> sources, ResultDescriptor result, |
| 4157 {isInstanceOf matcher: null}) { | 5609 {isInstanceOf matcher: null}) { |
| 4158 Map<ResultDescriptor, dynamic> compute(Source source) { | 5610 Map<ResultDescriptor, dynamic> compute(Source source) { |
| 4159 computeResult(new LibrarySpecificUnit(source, source), result, | 5611 computeResult(source, result, matcher: matcher); |
| 4160 matcher: matcher); | |
| 4161 return outputs; | 5612 return outputs; |
| 4162 } | 5613 } |
| 5614 |
| 4163 return sources.map(compute).toList(); | 5615 return sources.map(compute).toList(); |
| 4164 } | 5616 } |
| 4165 | 5617 |
| 4166 /** | 5618 /** |
| 4167 * Create a script object with a single fragment containing the given | 5619 * Create a script object with a single fragment containing the given |
| 4168 * [scriptContent]. | 5620 * [scriptContent]. |
| 4169 */ | 5621 */ |
| 4170 DartScript createScript(String scriptContent) { | 5622 DartScript createScript(String scriptContent) { |
| 4171 String htmlContent = ''' | 5623 String htmlContent = ''' |
| 4172 <!DOCTYPE html> | 5624 <!DOCTYPE html> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4185 | 5637 |
| 4186 /** | 5638 /** |
| 4187 * Enable strong mode in the current analysis context. | 5639 * Enable strong mode in the current analysis context. |
| 4188 */ | 5640 */ |
| 4189 void enableStrongMode() { | 5641 void enableStrongMode() { |
| 4190 AnalysisOptionsImpl options = context.analysisOptions; | 5642 AnalysisOptionsImpl options = context.analysisOptions; |
| 4191 options.strongMode = true; | 5643 options.strongMode = true; |
| 4192 context.analysisOptions = options; | 5644 context.analysisOptions = options; |
| 4193 } | 5645 } |
| 4194 | 5646 |
| 4195 /** | |
| 4196 * Return the declaration of the class with the given [className] in the given | |
| 4197 * compilation [unit]. | |
| 4198 */ | |
| 4199 ClassDeclaration getClass(CompilationUnit unit, String className) { | |
| 4200 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4201 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4202 if (unitMember is ClassDeclaration && unitMember.name.name == className) { | |
| 4203 return unitMember; | |
| 4204 } | |
| 4205 } | |
| 4206 fail('No class named $className in ${unit.element.source}'); | |
| 4207 return null; | |
| 4208 } | |
| 4209 | |
| 4210 /** | |
| 4211 * Return the declaration of the field with the given [fieldName] in the class | |
| 4212 * with the given [className] in the given compilation [unit]. | |
| 4213 */ | |
| 4214 VariableDeclaration getFieldInClass( | |
| 4215 CompilationUnit unit, String className, String fieldName) { | |
| 4216 ClassDeclaration unitMember = getClass(unit, className); | |
| 4217 NodeList<ClassMember> classMembers = unitMember.members; | |
| 4218 for (ClassMember classMember in classMembers) { | |
| 4219 if (classMember is FieldDeclaration) { | |
| 4220 NodeList<VariableDeclaration> fields = classMember.fields.variables; | |
| 4221 for (VariableDeclaration field in fields) { | |
| 4222 if (field.name.name == fieldName) { | |
| 4223 return field; | |
| 4224 } | |
| 4225 } | |
| 4226 } | |
| 4227 } | |
| 4228 fail('No field named $fieldName in $className'); | |
| 4229 return null; | |
| 4230 } | |
| 4231 | |
| 4232 /** | |
| 4233 * Return the declaration of the method with the given [methodName] in the | |
| 4234 * class with the given [className] in the given compilation [unit]. | |
| 4235 */ | |
| 4236 MethodDeclaration getMethodInClass( | |
| 4237 CompilationUnit unit, String className, String methodName) { | |
| 4238 ClassDeclaration unitMember = getClass(unit, className); | |
| 4239 NodeList<ClassMember> classMembers = unitMember.members; | |
| 4240 for (ClassMember classMember in classMembers) { | |
| 4241 if (classMember is MethodDeclaration) { | |
| 4242 if (classMember.name.name == methodName) { | |
| 4243 return classMember; | |
| 4244 } | |
| 4245 } | |
| 4246 } | |
| 4247 fail('No method named $methodName in $className'); | |
| 4248 return null; | |
| 4249 } | |
| 4250 | |
| 4251 List<Statement> getStatementsInMethod( | |
| 4252 CompilationUnit unit, String className, String methodName) { | |
| 4253 MethodDeclaration method = getMethodInClass(unit, className, methodName); | |
| 4254 BlockFunctionBody body = method.body; | |
| 4255 return body.block.statements; | |
| 4256 } | |
| 4257 | |
| 4258 List<Statement> getStatementsInTopLevelFunction( | |
| 4259 CompilationUnit unit, String functionName) { | |
| 4260 FunctionDeclaration function = getTopLevelFunction(unit, functionName); | |
| 4261 BlockFunctionBody body = function.functionExpression.body; | |
| 4262 return body.block.statements; | |
| 4263 } | |
| 4264 | |
| 4265 /** | |
| 4266 * Return the declaration of the top-level function with the given | |
| 4267 * [functionName] in the given compilation [unit]. | |
| 4268 */ | |
| 4269 FunctionDeclaration getTopLevelFunction( | |
| 4270 CompilationUnit unit, String functionName) { | |
| 4271 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4272 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4273 if (unitMember is FunctionDeclaration) { | |
| 4274 if (unitMember.name.name == functionName) { | |
| 4275 return unitMember; | |
| 4276 } | |
| 4277 } | |
| 4278 } | |
| 4279 return null; | |
| 4280 } | |
| 4281 | |
| 4282 /** | |
| 4283 * Return the declaration of the top-level variable with the given | |
| 4284 * [variableName] in the given compilation [unit]. | |
| 4285 */ | |
| 4286 VariableDeclaration getTopLevelVariable( | |
| 4287 CompilationUnit unit, String variableName) { | |
| 4288 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | |
| 4289 for (CompilationUnitMember unitMember in unitMembers) { | |
| 4290 if (unitMember is TopLevelVariableDeclaration) { | |
| 4291 NodeList<VariableDeclaration> variables = | |
| 4292 unitMember.variables.variables; | |
| 4293 for (VariableDeclaration variable in variables) { | |
| 4294 if (variable.name.name == variableName) { | |
| 4295 return variable; | |
| 4296 } | |
| 4297 } | |
| 4298 } | |
| 4299 } | |
| 4300 return null; | |
| 4301 } | |
| 4302 | |
| 4303 void setUp() { | 5647 void setUp() { |
| 4304 super.setUp(); | 5648 super.setUp(); |
| 4305 emptySource = newSource('/test.dart'); | 5649 emptySource = newSource('/test.dart'); |
| 4306 } | 5650 } |
| 4307 | 5651 |
| 4308 /** | 5652 /** |
| 4309 * Fill [errorListener] with [result] errors in the current [task]. | 5653 * Fill [errorListener] with [result] errors in the current [task]. |
| 4310 */ | 5654 */ |
| 4311 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5655 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4312 List<AnalysisError> errors = task.outputs[result]; | 5656 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
| 4313 expect(errors, isNotNull, reason: result.name); | 5657 expect(errors, isNotNull, reason: result.name); |
| 4314 errorListener = new GatheringErrorListener(); | 5658 errorListener = new GatheringErrorListener(); |
| 4315 errorListener.addAll(errors); | 5659 errorListener.addAll(errors); |
| 4316 } | 5660 } |
| 4317 } | 5661 } |
| OLD | NEW |