| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
| 13 hide AnalysisTask, GetContentTask, ParseDartTask, ScanDartTask; | 13 hide AnalysisTask, GetContentTask, ParseDartTask, ScanDartTask; |
| 14 import 'package:analyzer/src/generated/error.dart'; | 14 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/resolver.dart'; | 15 import 'package:analyzer/src/generated/resolver.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | |
| 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; | |
| 20 import 'package:analyzer/src/task/dart.dart'; | 18 import 'package:analyzer/src/task/dart.dart'; |
| 21 import 'package:analyzer/src/task/driver.dart'; | 19 import 'package:analyzer/src/task/driver.dart'; |
| 22 import 'package:analyzer/src/task/general.dart'; | 20 import 'package:analyzer/src/task/general.dart'; |
| 23 import 'package:analyzer/src/task/manager.dart'; | 21 import 'package:analyzer/src/task/manager.dart'; |
| 24 import 'package:analyzer/task/dart.dart'; | 22 import 'package:analyzer/task/dart.dart'; |
| 25 import 'package:analyzer/task/general.dart'; | 23 import 'package:analyzer/task/general.dart'; |
| 26 import 'package:analyzer/task/model.dart'; | 24 import 'package:analyzer/task/model.dart'; |
| 27 import 'package:typed_mock/typed_mock.dart'; | 25 import 'package:typed_mock/typed_mock.dart'; |
| 28 import 'package:unittest/unittest.dart'; | 26 import 'package:unittest/unittest.dart'; |
| 29 | 27 |
| 30 import '../../generated/test_support.dart'; | 28 import '../../generated/test_support.dart'; |
| 31 import '../../reflective_tests.dart'; | 29 import '../../reflective_tests.dart'; |
| 32 import '../mock_sdk.dart'; | 30 import '../mock_sdk.dart'; |
| 33 | 31 |
| 34 main() { | 32 main() { |
| 35 groupSep = ' | '; | 33 groupSep = ' | '; |
| 36 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 34 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 37 runReflectiveTests(BuildDirectiveElementsTaskTest); | 35 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 38 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 36 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 39 runReflectiveTests(BuildExportSourceClosureTaskTest); | 37 runReflectiveTests(BuildExportSourceClosureTaskTest); |
| 40 runReflectiveTests(BuildExportNamespaceTaskTest); | 38 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 41 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); | 39 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); |
| 42 runReflectiveTests(BuildLibraryElementTaskTest); | 40 runReflectiveTests(BuildLibraryElementTaskTest); |
| 43 runReflectiveTests(BuildPublicNamespaceTaskTest); | 41 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 44 runReflectiveTests(BuildTypeProviderTaskTest); | 42 runReflectiveTests(BuildTypeProviderTaskTest); |
| 45 runReflectiveTests(ParseDartTaskTest); | 43 runReflectiveTests(ParseDartTaskTest); |
| 46 runReflectiveTests(ResolveTypeNamesTaskTest); | 44 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 45 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 47 runReflectiveTests(ScanDartTaskTest); | 46 runReflectiveTests(ScanDartTaskTest); |
| 48 } | 47 } |
| 49 | 48 |
| 50 @reflectiveTest | 49 @reflectiveTest |
| 51 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 50 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 52 test_buildInputs() { | 51 test_buildInputs() { |
| 53 LibraryUnitTarget target = new LibraryUnitTarget(emptySource, emptySource); | 52 LibraryUnitTarget target = new LibraryUnitTarget(emptySource, emptySource); |
| 54 Map<String, TaskInput> inputs = | 53 Map<String, TaskInput> inputs = |
| 55 BuildCompilationUnitElementTask.buildInputs(target); | 54 BuildCompilationUnitElementTask.buildInputs(target); |
| 56 expect(inputs, isNotNull); | 55 expect(inputs, isNotNull); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void _performBuildTask(String content) { | 99 void _performBuildTask(String content) { |
| 101 Source source = _newSource('/test.dart', content); | 100 Source source = _newSource('/test.dart', content); |
| 102 AnalysisTarget target = new LibraryUnitTarget(source, source); | 101 AnalysisTarget target = new LibraryUnitTarget(source, source); |
| 103 _computeResult(target, RESOLVED_UNIT1); | 102 _computeResult(target, RESOLVED_UNIT1); |
| 104 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); | 103 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); |
| 105 } | 104 } |
| 106 } | 105 } |
| 107 | 106 |
| 108 @reflectiveTest | 107 @reflectiveTest |
| 109 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 108 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 110 test_buildInputs() { | |
| 111 ExtendedAnalysisContext context = new _MockContext(); | |
| 112 // prepare sources | |
| 113 File fileA = resourceProvider.newFile('/libA.dart', ''); | |
| 114 File fileB = resourceProvider.newFile('/libB.dart', ''); | |
| 115 File fileC = resourceProvider.newFile('/libC.dart', ''); | |
| 116 Source sourceA = fileA.createSource(); | |
| 117 Source sourceB = fileB.createSource(); | |
| 118 Source sourceC = fileC.createSource(); | |
| 119 // configure "sourceA" | |
| 120 CompilationUnit unitA = AstFactory.compilationUnit(); | |
| 121 context.getCacheEntry(sourceA).setValue( | |
| 122 IMPORTED_LIBRARIES, <Source>[sourceB]); | |
| 123 context.getCacheEntry(sourceA).setValue( | |
| 124 EXPORTED_LIBRARIES, <Source>[sourceC]); | |
| 125 context.getCacheEntry(sourceA).setValue(RESOLVED_UNIT2, unitA); | |
| 126 // configure "sourceB" | |
| 127 LibraryElement libraryElementB = ElementFactory.library(context, 'libB'); | |
| 128 context.getCacheEntry(sourceB).setValue(LIBRARY_ELEMENT1, libraryElementB); | |
| 129 context.getCacheEntry(sourceB).setValue(SOURCE_KIND, SourceKind.LIBRARY); | |
| 130 // configure "sourceC" | |
| 131 LibraryElement libraryElementC = ElementFactory.library(context, 'libC'); | |
| 132 context.getCacheEntry(sourceC).setValue(LIBRARY_ELEMENT1, libraryElementC); | |
| 133 context.getCacheEntry(sourceC).setValue(SOURCE_KIND, SourceKind.LIBRARY); | |
| 134 // request inputs | |
| 135 WorkItem workItem = | |
| 136 new WorkItem(context, sourceA, BuildDirectiveElementsTask.DESCRIPTOR); | |
| 137 workItem.gatherInputs(null); | |
| 138 Map<String, dynamic> inputs = workItem.inputs; | |
| 139 expect(inputs, hasLength(5)); | |
| 140 expect(inputs[BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME], unitA); | |
| 141 expect( | |
| 142 inputs[BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME], | |
| 143 containsPair(sourceB, libraryElementB)); | |
| 144 expect( | |
| 145 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME], | |
| 146 containsPair(sourceC, libraryElementC)); | |
| 147 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME], | |
| 148 containsPair(sourceB, SourceKind.LIBRARY)); | |
| 149 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME], | |
| 150 containsPair(sourceC, SourceKind.LIBRARY)); | |
| 151 } | |
| 152 | |
| 153 test_constructor() { | 109 test_constructor() { |
| 154 BuildDirectiveElementsTask task = | 110 BuildDirectiveElementsTask task = |
| 155 new BuildDirectiveElementsTask(context, emptySource); | 111 new BuildDirectiveElementsTask(context, emptySource); |
| 156 expect(task, isNotNull); | 112 expect(task, isNotNull); |
| 157 expect(task.context, context); | 113 expect(task.context, context); |
| 158 expect(task.target, emptySource); | 114 expect(task.target, emptySource); |
| 159 } | 115 } |
| 160 | 116 |
| 161 test_createTask() { | 117 test_createTask() { |
| 162 BuildDirectiveElementsTask task = | 118 BuildDirectiveElementsTask task = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 188 library libB; | 144 library libB; |
| 189 ''', | 145 ''', |
| 190 '/libC.dart': ''' | 146 '/libC.dart': ''' |
| 191 library libC; | 147 library libC; |
| 192 ''' | 148 ''' |
| 193 }); | 149 }); |
| 194 Source sourceA = sources[0]; | 150 Source sourceA = sources[0]; |
| 195 Source sourceB = sources[1]; | 151 Source sourceB = sources[1]; |
| 196 Source sourceC = sources[2]; | 152 Source sourceC = sources[2]; |
| 197 // perform task | 153 // perform task |
| 198 _computeResult(sourceA, RESOLVED_UNIT3); | 154 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 199 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 155 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 200 // prepare outputs | 156 // prepare outputs |
| 201 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 157 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; |
| 202 LibraryElement libraryElementA = libraryUnitA.element.library; | |
| 203 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); | 158 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); |
| 204 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); | 159 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); |
| 205 // no errors | 160 // no errors |
| 206 _assertErrorsWithCodes([]); | 161 _assertErrorsWithCodes([]); |
| 207 // validate directives | 162 // validate directives |
| 163 CompilationUnit libraryUnitA = context.getCacheEntry(new LibraryUnitTarget(s
ourceA, sourceA)).getValue(RESOLVED_UNIT1); |
| 208 { | 164 { |
| 209 ImportDirective importNode = libraryUnitA.directives[1]; | 165 ImportDirective importNode = libraryUnitA.directives[1]; |
| 210 ImportElement importElement = importNode.element; | 166 ImportElement importElement = importNode.element; |
| 211 expect(importElement, isNotNull); | 167 expect(importElement, isNotNull); |
| 212 expect(importElement.importedLibrary, libraryElementB); | 168 expect(importElement.importedLibrary, libraryElementB); |
| 213 expect(importElement.prefix, isNull); | 169 expect(importElement.prefix, isNull); |
| 214 expect(importElement.nameOffset, 14); | 170 expect(importElement.nameOffset, 14); |
| 215 expect(importElement.uriOffset, 21); | 171 expect(importElement.uriOffset, 21); |
| 216 expect(importElement.uriEnd, 32); | 172 expect(importElement.uriEnd, 32); |
| 217 } | 173 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 239 '/libA.dart': ''' | 195 '/libA.dart': ''' |
| 240 library libA; | 196 library libA; |
| 241 import 'libB.dart' show A, B hide C, D; | 197 import 'libB.dart' show A, B hide C, D; |
| 242 ''', | 198 ''', |
| 243 '/libB.dart': ''' | 199 '/libB.dart': ''' |
| 244 library libB; | 200 library libB; |
| 245 ''' | 201 ''' |
| 246 }); | 202 }); |
| 247 Source sourceA = sources[0]; | 203 Source sourceA = sources[0]; |
| 248 // perform task | 204 // perform task |
| 249 _computeResult(sourceA, RESOLVED_UNIT3); | 205 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 250 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 206 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 251 // prepare outputs | 207 // prepare outputs |
| 252 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 208 CompilationUnit libraryUnitA = context.getCacheEntry(new LibraryUnitTarget(s
ourceA, sourceA)).getValue(RESOLVED_UNIT1); |
| 253 // no errors | 209 // no errors |
| 254 _assertErrorsWithCodes([]); | 210 _assertErrorsWithCodes([]); |
| 255 // validate directives | 211 // validate directives |
| 256 ImportDirective importNode = libraryUnitA.directives[1]; | 212 ImportDirective importNode = libraryUnitA.directives[1]; |
| 257 ImportElement importElement = importNode.element; | 213 ImportElement importElement = importNode.element; |
| 258 List<NamespaceCombinator> combinators = importElement.combinators; | 214 List<NamespaceCombinator> combinators = importElement.combinators; |
| 259 expect(combinators, hasLength(2)); | 215 expect(combinators, hasLength(2)); |
| 260 { | 216 { |
| 261 ShowElementCombinator combinator = combinators[0]; | 217 ShowElementCombinator combinator = combinators[0]; |
| 262 expect(combinator.offset, 33); | 218 expect(combinator.offset, 33); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 274 '/libA.dart': ''' | 230 '/libA.dart': ''' |
| 275 library libA; | 231 library libA; |
| 276 export 'part.dart'; | 232 export 'part.dart'; |
| 277 ''', | 233 ''', |
| 278 '/part.dart': ''' | 234 '/part.dart': ''' |
| 279 part of notLib; | 235 part of notLib; |
| 280 ''' | 236 ''' |
| 281 }); | 237 }); |
| 282 Source sourceA = sources[0]; | 238 Source sourceA = sources[0]; |
| 283 // perform task | 239 // perform task |
| 284 _computeResult(sourceA, RESOLVED_UNIT3); | 240 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 285 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 241 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 286 // validate errors | 242 // validate errors |
| 287 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); | 243 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 288 } | 244 } |
| 289 | 245 |
| 290 test_perform_error_importOfNonLibrary() { | 246 test_perform_error_importOfNonLibrary() { |
| 291 List<Source> sources = _newSources({ | 247 List<Source> sources = _newSources({ |
| 292 '/libA.dart': ''' | 248 '/libA.dart': ''' |
| 293 library libA; | 249 library libA; |
| 294 import 'part.dart'; | 250 import 'part.dart'; |
| 295 ''', | 251 ''', |
| 296 '/part.dart': ''' | 252 '/part.dart': ''' |
| 297 part of notLib; | 253 part of notLib; |
| 298 ''' | 254 ''' |
| 299 }); | 255 }); |
| 300 Source sourceA = sources[0]; | 256 Source sourceA = sources[0]; |
| 301 // perform task | 257 // perform task |
| 302 _computeResult(sourceA, RESOLVED_UNIT3); | 258 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 303 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 259 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 304 // validate errors | 260 // validate errors |
| 305 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 261 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 306 } | 262 } |
| 307 | 263 |
| 308 test_perform_hasExtUri() { | 264 test_perform_hasExtUri() { |
| 309 List<Source> sources = _newSources({ | 265 List<Source> sources = _newSources({ |
| 310 '/lib.dart': ''' | 266 '/lib.dart': ''' |
| 311 import 'dart-ext:doesNotExist.dart'; | 267 import 'dart-ext:doesNotExist.dart'; |
| 312 ''' | 268 ''' |
| 313 }); | 269 }); |
| 314 Source source = sources[0]; | 270 Source source = sources[0]; |
| 315 // perform task | 271 // perform task |
| 316 _computeResult(source, RESOLVED_UNIT3); | 272 _computeResult(source, LIBRARY_ELEMENT2); |
| 317 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 273 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 318 // prepare outputs | 274 // prepare outputs |
| 319 CompilationUnit libraryUnit = outputs[RESOLVED_UNIT3]; | 275 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 320 LibraryElement libraryElement = libraryUnit.element.library; | |
| 321 expect(libraryElement.hasExtUri, isTrue); | 276 expect(libraryElement.hasExtUri, isTrue); |
| 322 } | 277 } |
| 323 | 278 |
| 324 test_perform_importPrefix() { | 279 test_perform_importPrefix() { |
| 325 List<Source> sources = _newSources({ | 280 List<Source> sources = _newSources({ |
| 326 '/libA.dart': ''' | 281 '/libA.dart': ''' |
| 327 library libA; | 282 library libA; |
| 328 import 'libB.dart' as pref; | 283 import 'libB.dart' as pref; |
| 329 import 'libC.dart' as pref; | 284 import 'libC.dart' as pref; |
| 330 ''', | 285 ''', |
| 331 '/libB.dart': ''' | 286 '/libB.dart': ''' |
| 332 library libB; | 287 library libB; |
| 333 ''', | 288 ''', |
| 334 '/libC.dart': ''' | 289 '/libC.dart': ''' |
| 335 library libC; | 290 library libC; |
| 336 ''' | 291 ''' |
| 337 }); | 292 }); |
| 338 Source sourceA = sources[0]; | 293 Source sourceA = sources[0]; |
| 339 Source sourceB = sources[1]; | 294 Source sourceB = sources[1]; |
| 340 // perform task | 295 // perform task |
| 341 _computeResult(sourceA, RESOLVED_UNIT3); | 296 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 342 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 297 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 343 // prepare outputs | 298 // prepare outputs |
| 344 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 299 CompilationUnit libraryUnitA = context.getCacheEntry(new LibraryUnitTarget(s
ourceA, sourceA)).getValue(RESOLVED_UNIT1); |
| 345 // validate directives | 300 // validate directives |
| 346 { | 301 { |
| 347 ImportDirective importNodeB = libraryUnitA.directives[1]; | 302 ImportDirective importNodeB = libraryUnitA.directives[1]; |
| 348 SimpleIdentifier prefixNodeB = importNodeB.prefix; | 303 SimpleIdentifier prefixNodeB = importNodeB.prefix; |
| 349 ImportElement importElementB = importNodeB.element; | 304 ImportElement importElementB = importNodeB.element; |
| 350 PrefixElement prefixElement = importElementB.prefix; | 305 PrefixElement prefixElement = importElementB.prefix; |
| 351 expect(importElementB, isNotNull); | 306 expect(importElementB, isNotNull); |
| 352 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); | 307 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); |
| 353 expect(prefixElement, isNotNull); | 308 expect(prefixElement, isNotNull); |
| 354 expect(importElementB.prefixOffset, prefixElement.nameOffset); | 309 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 379 } | 334 } |
| 380 | 335 |
| 381 @reflectiveTest | 336 @reflectiveTest |
| 382 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 337 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 383 test_perform() { | 338 test_perform() { |
| 384 Source source = _newSource('/test.dart', ''' | 339 Source source = _newSource('/test.dart', ''' |
| 385 enum MyEnum { | 340 enum MyEnum { |
| 386 A, B | 341 A, B |
| 387 } | 342 } |
| 388 '''); | 343 '''); |
| 389 _computeResult(source, RESOLVED_UNIT4); | 344 _computeResult(new LibraryUnitTarget(source, source), RESOLVED_UNIT2); |
| 390 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); | 345 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); |
| 391 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 346 CompilationUnit unit = outputs[RESOLVED_UNIT2]; |
| 392 // validate Element | 347 // validate Element |
| 393 ClassElement enumElement = unit.element.getEnum('MyEnum'); | 348 ClassElement enumElement = unit.element.getEnum('MyEnum'); |
| 394 List<FieldElement> fields = enumElement.fields; | 349 List<FieldElement> fields = enumElement.fields; |
| 395 expect(fields, hasLength(4)); | 350 expect(fields, hasLength(4)); |
| 396 { | 351 { |
| 397 FieldElementImpl index = fields[0]; | 352 FieldElementImpl index = fields[0]; |
| 398 expect(index, isNotNull); | 353 expect(index, isNotNull); |
| 399 expect(index.name, 'index'); | 354 expect(index.name, 'index'); |
| 400 expect(index.isStatic, isFalse); | 355 expect(index.isStatic, isFalse); |
| 401 expect(index.evaluationResult, isNull); | 356 expect(index.evaluationResult, isNull); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 static void _assertGetter(FieldElement field) { | 390 static void _assertGetter(FieldElement field) { |
| 436 PropertyAccessorElement getter = field.getter; | 391 PropertyAccessorElement getter = field.getter; |
| 437 expect(getter, isNotNull); | 392 expect(getter, isNotNull); |
| 438 expect(getter.variable, same(field)); | 393 expect(getter.variable, same(field)); |
| 439 expect(getter.type, isNotNull); | 394 expect(getter.type, isNotNull); |
| 440 } | 395 } |
| 441 } | 396 } |
| 442 | 397 |
| 443 @reflectiveTest | 398 @reflectiveTest |
| 444 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { | 399 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { |
| 445 test_perform_entyrPoint() { | 400 test_perform_entryPoint() { |
| 446 Source sourceA = _newSource('/a.dart', ''' | 401 Source sourceA = _newSource('/a.dart', ''' |
| 447 library lib_a; | 402 library lib_a; |
| 448 export 'b.dart'; | 403 export 'b.dart'; |
| 449 '''); | 404 '''); |
| 450 Source sourceB = _newSource('/b.dart', ''' | 405 Source sourceB = _newSource('/b.dart', ''' |
| 451 library lib_b; | 406 library lib_b; |
| 452 main() {} | 407 main() {} |
| 453 '''); | 408 '''); |
| 454 _computeResult(sourceA, LIBRARY_ELEMENT4); | 409 _computeResult(sourceA, LIBRARY_ELEMENT4); |
| 455 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 410 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 539 } |
| 585 | 540 |
| 586 @reflectiveTest | 541 @reflectiveTest |
| 587 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { | 542 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { |
| 588 test_perform() { | 543 test_perform() { |
| 589 Source source = _newSource('/test.dart', ''' | 544 Source source = _newSource('/test.dart', ''' |
| 590 typedef int F(G g); | 545 typedef int F(G g); |
| 591 typedef String G(int p); | 546 typedef String G(int p); |
| 592 '''); | 547 '''); |
| 593 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 548 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 594 _computeResult(target, RESOLVED_UNIT5); | 549 _computeResult(target, RESOLVED_UNIT3); |
| 595 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | 550 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); |
| 596 // validate | 551 // validate |
| 597 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 552 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 598 FunctionTypeAlias nodeF = unit.declarations[0]; | 553 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 599 FunctionTypeAlias nodeG = unit.declarations[1]; | 554 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 600 { | 555 { |
| 601 FormalParameter parameter = nodeF.parameters.parameters[0]; | 556 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 602 DartType parameterType = parameter.element.type; | 557 DartType parameterType = parameter.element.type; |
| 603 Element returnTypeElement = nodeF.returnType.type.element; | 558 Element returnTypeElement = nodeF.returnType.type.element; |
| 604 expect(returnTypeElement.displayName, 'int'); | 559 expect(returnTypeElement.displayName, 'int'); |
| 605 expect(parameterType.element, nodeG.element); | 560 expect(parameterType.element, nodeG.element); |
| 606 } | 561 } |
| 607 { | 562 { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 part 'part1.dart'; | 624 part 'part1.dart'; |
| 670 part 'part2.dart'; | 625 part 'part2.dart'; |
| 671 ''', | 626 ''', |
| 672 '/part1.dart': ''' | 627 '/part1.dart': ''' |
| 673 part of lib; | 628 part of lib; |
| 674 ''', | 629 ''', |
| 675 '/part2.dart': ''' | 630 '/part2.dart': ''' |
| 676 part of lib; | 631 part of lib; |
| 677 ''' | 632 ''' |
| 678 }); | 633 }); |
| 679 expect(outputs, hasLength(5)); | 634 expect(outputs, hasLength(4)); |
| 680 // simple outputs | 635 // simple outputs |
| 681 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); | 636 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); |
| 682 expect(outputs[RESOLVED_UNIT2], same(libraryUnit)); | |
| 683 expect(outputs[IS_LAUNCHABLE], isFalse); | 637 expect(outputs[IS_LAUNCHABLE], isFalse); |
| 684 expect(outputs[HAS_HTML_IMPORT], isFalse); | 638 expect(outputs[HAS_HTML_IMPORT], isFalse); |
| 685 // LibraryElement output | 639 // LibraryElement output |
| 686 expect(libraryElement, isNotNull); | 640 expect(libraryElement, isNotNull); |
| 687 expect(libraryElement.entryPoint, isNull); | 641 expect(libraryElement.entryPoint, isNull); |
| 688 expect(libraryElement.source, same(librarySource)); | 642 expect(libraryElement.source, same(librarySource)); |
| 689 expect(libraryElement.definingCompilationUnit, libraryUnitElement); | 643 expect(libraryElement.definingCompilationUnit, libraryUnitElement); |
| 690 expect(libraryElement.parts, | 644 expect(libraryElement.parts, |
| 691 unorderedEquals([partUnits[0].element, partUnits[1].element])); | 645 unorderedEquals([partUnits[0].element, partUnits[1].element])); |
| 692 // LibraryElement references | 646 // LibraryElement references |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 expect(unitElement2.topLevelVariables, [variable]); | 803 expect(unitElement2.topLevelVariables, [variable]); |
| 850 } | 804 } |
| 851 | 805 |
| 852 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 806 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 853 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 807 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 854 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 808 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 855 } | 809 } |
| 856 | 810 |
| 857 void _performBuildTask(Map<String, String> sourceMap) { | 811 void _performBuildTask(Map<String, String> sourceMap) { |
| 858 List<Source> sources = _newSources(sourceMap); | 812 List<Source> sources = _newSources(sourceMap); |
| 859 _computeResult(sources.first, RESOLVED_UNIT2); | 813 Source libSource = sources.first; |
| 814 _computeResult(libSource, LIBRARY_ELEMENT1); |
| 860 expect(task, new isInstanceOf<BuildLibraryElementTask>()); | 815 expect(task, new isInstanceOf<BuildLibraryElementTask>()); |
| 861 libraryUnit = outputs[RESOLVED_UNIT2]; | 816 libraryUnit = context.getCacheEntry(new LibraryUnitTarget(libSource, libSour
ce)).getValue(RESOLVED_UNIT1); |
| 862 libraryUnitElement = libraryUnit.element; | 817 libraryUnitElement = libraryUnit.element; |
| 863 librarySource = libraryUnitElement.source; | 818 librarySource = libraryUnitElement.source; |
| 864 libraryElement = outputs[LIBRARY_ELEMENT1]; | 819 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 865 partUnits = | 820 partUnits = |
| 866 task.inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME]; | 821 task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; |
| 867 } | 822 } |
| 868 } | 823 } |
| 869 | 824 |
| 870 @reflectiveTest | 825 @reflectiveTest |
| 871 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { | 826 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { |
| 872 test_buildInputs() { | 827 test_buildInputs() { |
| 873 Map<String, TaskInput> inputs = | 828 Map<String, TaskInput> inputs = |
| 874 BuildPublicNamespaceTask.buildInputs(emptySource); | 829 BuildPublicNamespaceTask.buildInputs(emptySource); |
| 875 expect(inputs, isNotNull); | 830 expect(inputs, isNotNull); |
| 876 expect( | 831 expect( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 | 985 |
| 1031 static void _assertHasCore(List<Source> sources, int lenght) { | 986 static void _assertHasCore(List<Source> sources, int lenght) { |
| 1032 expect(sources, hasLength(lenght)); | 987 expect(sources, hasLength(lenght)); |
| 1033 expect(sources, contains(predicate((Source s) { | 988 expect(sources, contains(predicate((Source s) { |
| 1034 return s.fullName.endsWith('core.dart'); | 989 return s.fullName.endsWith('core.dart'); |
| 1035 }))); | 990 }))); |
| 1036 } | 991 } |
| 1037 } | 992 } |
| 1038 | 993 |
| 1039 @reflectiveTest | 994 @reflectiveTest |
| 1040 class ResolveTypeNamesTaskTest extends _AbstractDartTaskTest { | 995 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 996 test_perform() { |
| 997 Source sourceLib = _newSource('/my_lib.dart', ''' |
| 998 library my_lib; |
| 999 part 'my_part.dart'; |
| 1000 class A {} |
| 1001 class B extends A {} |
| 1002 '''); |
| 1003 _newSource('/my_part.dart', ''' |
| 1004 part of my_lib; |
| 1005 class C extends A {} |
| 1006 '''); |
| 1007 _computeResult(sourceLib, LIBRARY_ELEMENT5); |
| 1008 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); |
| 1009 // validate |
| 1010 LibraryElement library = outputs[LIBRARY_ELEMENT5]; |
| 1011 { |
| 1012 ClassElement classB = library.getType('B'); |
| 1013 expect(classB.supertype.displayName, 'A'); |
| 1014 } |
| 1015 { |
| 1016 ClassElement classC = library.getType('C'); |
| 1017 expect(classC.supertype.displayName, 'A'); |
| 1018 } |
| 1019 } |
| 1020 } |
| 1021 |
| 1022 @reflectiveTest |
| 1023 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 1041 test_perform() { | 1024 test_perform() { |
| 1042 Source source = _newSource('/test.dart', ''' | 1025 Source source = _newSource('/test.dart', ''' |
| 1043 class A {} | 1026 class A {} |
| 1044 class B extends A {} | 1027 class B extends A {} |
| 1045 int f(String p) => p.length; | 1028 int f(String p) => p.length; |
| 1046 '''); | 1029 '''); |
| 1047 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1030 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1048 _computeResult(target, RESOLVED_UNIT6); | 1031 _computeResult(target, RESOLVED_UNIT4); |
| 1049 expect(task, new isInstanceOf<ResolveTypeNamesTask>()); | 1032 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1050 // validate | 1033 // validate |
| 1051 CompilationUnit unit = outputs[RESOLVED_UNIT6]; | 1034 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 1052 { | 1035 { |
| 1053 ClassDeclaration nodeA = unit.declarations[0]; | 1036 ClassDeclaration nodeA = unit.declarations[0]; |
| 1054 ClassDeclaration nodeB = unit.declarations[1]; | 1037 ClassDeclaration nodeB = unit.declarations[1]; |
| 1055 DartType extendsType = nodeB.extendsClause.superclass.type; | 1038 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 1056 expect(extendsType, nodeA.element.type); | 1039 expect(extendsType, nodeA.element.type); |
| 1057 } | 1040 } |
| 1058 { | 1041 { |
| 1059 FunctionDeclaration functionNode = unit.declarations[2]; | 1042 FunctionDeclaration functionNode = unit.declarations[2]; |
| 1060 DartType returnType = functionNode.returnType.type; | 1043 DartType returnType = functionNode.returnType.type; |
| 1061 List<FormalParameter> parameters = | 1044 List<FormalParameter> parameters = |
| 1062 functionNode.functionExpression.parameters.parameters; | 1045 functionNode.functionExpression.parameters.parameters; |
| 1063 expect(returnType.displayName, 'int'); | 1046 expect(returnType.displayName, 'int'); |
| 1064 expect(parameters[0].element.type.displayName, 'String'); | 1047 expect(parameters[0].element.type.displayName, 'String'); |
| 1065 } | 1048 } |
| 1066 } | 1049 } |
| 1067 | 1050 |
| 1068 test_perform_errors() { | 1051 test_perform_errors() { |
| 1069 Source source = _newSource('/test.dart', ''' | 1052 Source source = _newSource('/test.dart', ''' |
| 1070 NoSuchClass f() => null; | 1053 NoSuchClass f() => null; |
| 1071 '''); | 1054 '''); |
| 1072 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1055 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1073 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 1056 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 1074 expect(task, new isInstanceOf<ResolveTypeNamesTask>()); | 1057 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1075 // validate | 1058 // validate |
| 1076 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 1059 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 1077 errorListener | 1060 errorListener |
| 1078 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 1061 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 1079 } | 1062 } |
| 1080 } | 1063 } |
| 1081 | 1064 |
| 1082 @reflectiveTest | 1065 @reflectiveTest |
| 1083 class ScanDartTaskTest extends _AbstractDartTaskTest { | 1066 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 1084 test_buildInputs() { | 1067 test_buildInputs() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR); | 1149 taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR); |
| 1167 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); | 1150 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); |
| 1168 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); | 1151 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 1169 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); | 1152 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 1170 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); | 1153 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 1171 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); | 1154 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); |
| 1172 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); | 1155 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); |
| 1173 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); | 1156 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); |
| 1174 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); | 1157 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); |
| 1175 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); | 1158 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); |
| 1176 taskManager.addTaskDescriptor(ResolveTypeNamesTask.DESCRIPTOR); | 1159 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 1160 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 1177 // prepare AnalysisDriver | 1161 // prepare AnalysisDriver |
| 1178 analysisDriver = new AnalysisDriver(taskManager, context); | 1162 analysisDriver = new AnalysisDriver(taskManager, context); |
| 1179 } | 1163 } |
| 1180 | 1164 |
| 1181 void _computeResult(AnalysisTarget target, ResultDescriptor result) { | 1165 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 1182 task = analysisDriver.computeResult(target, result); | 1166 task = analysisDriver.computeResult(target, result); |
| 1183 expect(task.caughtException, isNull); | 1167 expect(task.caughtException, isNull); |
| 1184 outputs = task.outputs; | 1168 outputs = task.outputs; |
| 1185 } | 1169 } |
| 1186 | 1170 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1210 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1227 } | 1211 } |
| 1228 | 1212 |
| 1229 TimestampedData<String> getContents(Source source) => source.contents; | 1213 TimestampedData<String> getContents(Source source) => source.contents; |
| 1230 | 1214 |
| 1231 noSuchMethod(Invocation invocation) { | 1215 noSuchMethod(Invocation invocation) { |
| 1232 print('noSuchMethod: ${invocation.memberName}'); | 1216 print('noSuchMethod: ${invocation.memberName}'); |
| 1233 return super.noSuchMethod(invocation); | 1217 return super.noSuchMethod(invocation); |
| 1234 } | 1218 } |
| 1235 } | 1219 } |
| OLD | NEW |