| 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/memory_file_system.dart'; |
| 15 import 'package:analyzer/file_system/physical_file_system.dart'; | 15 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 16 import 'package:analyzer/src/context/context.dart'; | 16 import 'package:analyzer/src/context/context.dart'; |
| 17 import 'package:analyzer/src/dart/element/element.dart'; | 17 import 'package:analyzer/src/dart/element/element.dart'; |
| 18 import 'package:analyzer/src/dart/element/type.dart'; | 18 import 'package:analyzer/src/dart/element/type.dart'; |
| 19 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 19 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/resolver.dart'; | 21 import 'package:analyzer/src/generated/resolver.dart'; |
| 22 import 'package:analyzer/src/generated/sdk.dart'; | 22 import 'package:analyzer/src/generated/sdk.dart'; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 23 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 26 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_dart.dart'; | 27 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 28 import 'package:analyzer/src/source/source_resource.dart'; | |
| 29 import 'package:analyzer/src/string_source.dart'; | 28 import 'package:analyzer/src/string_source.dart'; |
| 30 import 'package:test/test.dart'; | 29 import 'package:test/test.dart'; |
| 31 | 30 |
| 32 /** | 31 /** |
| 33 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 32 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 34 * for testing purposes. | 33 * for testing purposes. |
| 35 */ | 34 */ |
| 36 class AnalysisContextFactory { | 35 class AnalysisContextFactory { |
| 37 static String _DART_MATH = "dart:math"; | 36 static String _DART_MATH = "dart:math"; |
| 38 | 37 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 */ | 481 */ |
| 483 void _internalSetAnalysisOptions(AnalysisOptions options) { | 482 void _internalSetAnalysisOptions(AnalysisOptions options) { |
| 484 super.analysisOptions = options; | 483 super.analysisOptions = options; |
| 485 } | 484 } |
| 486 } | 485 } |
| 487 | 486 |
| 488 /** | 487 /** |
| 489 * Helper for creating and managing single [AnalysisContext]. | 488 * Helper for creating and managing single [AnalysisContext]. |
| 490 */ | 489 */ |
| 491 class AnalysisContextHelper { | 490 class AnalysisContextHelper { |
| 492 ResourceProvider resourceProvider; | 491 MemoryResourceProvider resourceProvider; |
| 493 AnalysisContext context; | 492 AnalysisContext context; |
| 494 | 493 |
| 495 /** | 494 /** |
| 496 * Creates new [AnalysisContext] using [AnalysisContextFactory]. | 495 * Creates new [AnalysisContext] using [AnalysisContextFactory]. |
| 497 */ | 496 */ |
| 498 AnalysisContextHelper( | 497 AnalysisContextHelper( |
| 499 [AnalysisOptionsImpl options, ResourceProvider provider]) { | 498 [AnalysisOptionsImpl options, MemoryResourceProvider provider]) { |
| 500 resourceProvider = provider ?? new MemoryResourceProvider(); | 499 resourceProvider = provider ?? new MemoryResourceProvider(); |
| 501 if (options == null) { | 500 context = AnalysisContextFactory.contextWithCoreAndOptions( |
| 502 options = new AnalysisOptionsImpl(); | 501 options ?? new AnalysisOptionsImpl(), |
| 503 } | |
| 504 context = AnalysisContextFactory.contextWithCoreAndOptions(options, | |
| 505 resourceProvider: resourceProvider); | 502 resourceProvider: resourceProvider); |
| 506 } | 503 } |
| 507 | 504 |
| 508 Source addSource(String path, String code) { | 505 Source addSource(String path, String code) { |
| 509 Source source = new FileSource(resourceProvider.getFile(path)); | 506 Source source = resourceProvider |
| 507 .getFile(resourceProvider.convertPath(path)) |
| 508 .createSource(); |
| 510 if (path.endsWith(".dart") || path.endsWith(".html")) { | 509 if (path.endsWith(".dart") || path.endsWith(".html")) { |
| 511 ChangeSet changeSet = new ChangeSet(); | 510 ChangeSet changeSet = new ChangeSet(); |
| 512 changeSet.addedSource(source); | 511 changeSet.addedSource(source); |
| 513 context.applyChanges(changeSet); | 512 context.applyChanges(changeSet); |
| 514 } | 513 } |
| 515 context.setContents(source, code); | 514 context.setContents(source, code); |
| 516 return source; | 515 return source; |
| 517 } | 516 } |
| 518 | 517 |
| 519 CompilationUnitElement getDefiningUnitElement(Source source) => | 518 CompilationUnitElement getDefiningUnitElement(Source source) => |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 571 |
| 573 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { | 572 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { |
| 574 SdkLibraryImpl library = new SdkLibraryImpl(uri); | 573 SdkLibraryImpl library = new SdkLibraryImpl(uri); |
| 575 if (isInternal) { | 574 if (isInternal) { |
| 576 library.category = "Internal"; | 575 library.category = "Internal"; |
| 577 } | 576 } |
| 578 library.path = path; | 577 library.path = path; |
| 579 map.setLibrary(uri, library); | 578 map.setLibrary(uri, library); |
| 580 } | 579 } |
| 581 } | 580 } |
| OLD | NEW |