| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Utility functions to test the code generation tools with the resolver. | 5 /// Utility functions to test the code generation tools with the resolver. |
| 6 // Note, this is just for simple tests, so we restricted the logic to only | 6 // Note, this is just for simple tests, so we restricted the logic to only |
| 7 // support root-relative imports. For more sophisticated stuff, you should be | 7 // support root-relative imports. For more sophisticated stuff, you should be |
| 8 // using the test helpers in `package:code_transformers`. | 8 // using the test helpers in `package:code_transformers`. |
| 9 library smoke.test.codegen.testing_resolver_utils; | 9 library smoke.test.codegen.testing_resolver_utils; |
| 10 | 10 |
| 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 import 'package:analyzer/src/generated/java_io.dart'; | 13 import 'package:analyzer/src/generated/java_io.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 15 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 16 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; | 16 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; |
| 17 | 17 |
| 18 class LibraryProvider { | 18 class LibraryProvider { |
| 19 final AnalysisContext _analyzer; | 19 final AnalysisContext _analyzer; |
| 20 final Map<String, Source> _allSources; | 20 final Map<String, Source> _allSources; |
| 21 LibraryProvider(this._analyzer, this._allSources); | 21 LibraryProvider(this._analyzer, this._allSources); |
| 22 LibraryElement libraryFor(String uri) => | 22 LibraryElement libraryFor(String uri) => |
| 23 _analyzer.computeLibraryElement(_allSources[uri]); | 23 _analyzer.computeLibraryElement(_allSources[uri]); |
| 24 } | 24 } |
| 25 | 25 |
| 26 LibraryProvider initAnalyzer(Map<String, String> contents) { | 26 LibraryProvider initAnalyzer(Map<String, String> contents) { |
| 27 AnalysisEngine.instance.processRequiredPlugins(); |
| 27 var analyzer = AnalysisEngine.instance.createAnalysisContext(); | 28 var analyzer = AnalysisEngine.instance.createAnalysisContext(); |
| 28 var options = new AnalysisOptionsImpl() | 29 var options = new AnalysisOptionsImpl() |
| 29 ..cacheSize = 256 | 30 ..cacheSize = 256 |
| 30 ..preserveComments = false | 31 ..preserveComments = false |
| 31 ..analyzeFunctionBodies = false; | 32 ..analyzeFunctionBodies = false; |
| 32 analyzer.analysisOptions = options; | 33 analyzer.analysisOptions = options; |
| 33 var sdk = new DirectoryBasedDartSdk(new JavaFile(testingDartSdkDirectory)); | 34 var sdk = new DirectoryBasedDartSdk(new JavaFile(testingDartSdkDirectory)); |
| 34 sdk.context.analysisOptions = options; | 35 sdk.context.analysisOptions = options; |
| 35 var changes = new ChangeSet(); | 36 var changes = new ChangeSet(); |
| 36 var allSources = {}; | 37 var allSources = {}; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (!uri.path.startsWith('/')) { | 100 if (!uri.path.startsWith('/')) { |
| 100 throw new UnimplementedError('relative URIs not supported: $uri'); | 101 throw new UnimplementedError('relative URIs not supported: $uri'); |
| 101 } | 102 } |
| 102 return uri; | 103 return uri; |
| 103 } | 104 } |
| 104 | 105 |
| 105 void getContentsToReceiver(Source_ContentReceiver receiver) { | 106 void getContentsToReceiver(Source_ContentReceiver receiver) { |
| 106 receiver.accept(rawContents, modificationStamp); | 107 receiver.accept(rawContents, modificationStamp); |
| 107 } | 108 } |
| 108 } | 109 } |
| OLD | NEW |