| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.generated.analysis_context_factory; | 5 library analyzer.test.generated.analysis_context_factory; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 14 import 'package:analyzer/file_system/physical_file_system.dart'; | 15 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 15 import 'package:analyzer/src/context/context.dart'; | 16 import 'package:analyzer/src/context/context.dart'; |
| 16 import 'package:analyzer/src/dart/element/element.dart'; | 17 import 'package:analyzer/src/dart/element/element.dart'; |
| 17 import 'package:analyzer/src/dart/element/type.dart'; | 18 import 'package:analyzer/src/dart/element/type.dart'; |
| 18 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 19 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/java_engine_io.dart'; | 21 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 21 import 'package:analyzer/src/generated/resolver.dart'; | 22 import 'package:analyzer/src/generated/resolver.dart'; |
| 22 import 'package:analyzer/src/generated/sdk.dart'; | 23 import 'package:analyzer/src/generated/sdk.dart'; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 24 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 27 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_dart.dart'; | 28 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 29 import 'package:analyzer/src/source/source_resource.dart'; |
| 28 import 'package:analyzer/src/string_source.dart'; | 30 import 'package:analyzer/src/string_source.dart'; |
| 29 import 'package:unittest/unittest.dart'; | 31 import 'package:unittest/unittest.dart'; |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 34 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 33 * for testing purposes. | 35 * for testing purposes. |
| 34 */ | 36 */ |
| 35 class AnalysisContextFactory { | 37 class AnalysisContextFactory { |
| 36 static String _DART_MATH = "dart:math"; | 38 static String _DART_MATH = "dart:math"; |
| 37 | 39 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 */ | 494 */ |
| 493 void _internalSetAnalysisOptions(AnalysisOptions options) { | 495 void _internalSetAnalysisOptions(AnalysisOptions options) { |
| 494 super.analysisOptions = options; | 496 super.analysisOptions = options; |
| 495 } | 497 } |
| 496 } | 498 } |
| 497 | 499 |
| 498 /** | 500 /** |
| 499 * Helper for creating and managing single [AnalysisContext]. | 501 * Helper for creating and managing single [AnalysisContext]. |
| 500 */ | 502 */ |
| 501 class AnalysisContextHelper { | 503 class AnalysisContextHelper { |
| 504 ResourceProvider resourceProvider; |
| 502 AnalysisContext context; | 505 AnalysisContext context; |
| 503 | 506 |
| 504 /** | 507 /** |
| 505 * Creates new [AnalysisContext] using [AnalysisContextFactory]. | 508 * Creates new [AnalysisContext] using [AnalysisContextFactory]. |
| 506 */ | 509 */ |
| 507 AnalysisContextHelper([AnalysisOptionsImpl options]) { | 510 AnalysisContextHelper( |
| 511 [AnalysisOptionsImpl options, ResourceProvider provider]) { |
| 512 resourceProvider = provider ?? new MemoryResourceProvider(); |
| 508 if (options == null) { | 513 if (options == null) { |
| 509 options = new AnalysisOptionsImpl(); | 514 options = new AnalysisOptionsImpl(); |
| 510 } | 515 } |
| 511 options.cacheSize = 256; | 516 options.cacheSize = 256; |
| 512 context = AnalysisContextFactory.contextWithCoreAndOptions(options); | 517 context = AnalysisContextFactory.contextWithCoreAndOptions(options, |
| 518 resourceProvider: resourceProvider); |
| 513 } | 519 } |
| 514 | 520 |
| 515 Source addSource(String path, String code) { | 521 Source addSource(String path, String code) { |
| 516 Source source = new FileBasedSource(FileUtilities2.createFile(path)); | 522 Source source = new FileSource(resourceProvider.getFile(path)); |
| 517 if (path.endsWith(".dart") || path.endsWith(".html")) { | 523 if (path.endsWith(".dart") || path.endsWith(".html")) { |
| 518 ChangeSet changeSet = new ChangeSet(); | 524 ChangeSet changeSet = new ChangeSet(); |
| 519 changeSet.addedSource(source); | 525 changeSet.addedSource(source); |
| 520 context.applyChanges(changeSet); | 526 context.applyChanges(changeSet); |
| 521 } | 527 } |
| 522 context.setContents(source, code); | 528 context.setContents(source, code); |
| 523 return source; | 529 return source; |
| 524 } | 530 } |
| 525 | 531 |
| 526 CompilationUnitElement getDefiningUnitElement(Source source) => | 532 CompilationUnitElement getDefiningUnitElement(Source source) => |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 | 589 |
| 584 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { | 590 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { |
| 585 SdkLibraryImpl library = new SdkLibraryImpl(uri); | 591 SdkLibraryImpl library = new SdkLibraryImpl(uri); |
| 586 if (isInternal) { | 592 if (isInternal) { |
| 587 library.category = "Internal"; | 593 library.category = "Internal"; |
| 588 } | 594 } |
| 589 library.path = path; | 595 library.path = path; |
| 590 map.setLibrary(uri, library); | 596 map.setLibrary(uri, library); |
| 591 } | 597 } |
| 592 } | 598 } |
| OLD | NEW |