| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/context/declared_variables.dart'; | 5 import 'package:analyzer/context/declared_variables.dart'; |
| 6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; | 7 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; |
| 8 import 'package:analyzer/error/error.dart'; | 8 import 'package:analyzer/error/error.dart'; |
| 9 import 'package:analyzer/src/context/context.dart'; | 9 import 'package:analyzer/src/context/context.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 11 import 'package:analyzer/src/dart/analysis/driver.dart'; | 11 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 13 import 'package:analyzer/src/dart/analysis/file_tracker.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 14 show AnalysisContext, AnalysisEngine, AnalysisOptions; | 15 show AnalysisContext, AnalysisEngine, AnalysisOptions; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/summary/format.dart'; | 17 import 'package:analyzer/src/summary/format.dart'; |
| 17 import 'package:analyzer/src/summary/idl.dart'; | 18 import 'package:analyzer/src/summary/idl.dart'; |
| 18 import 'package:analyzer/src/summary/link.dart'; | 19 import 'package:analyzer/src/summary/link.dart'; |
| 19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 20 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; | 21 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; |
| 21 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; | 22 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; |
| 22 | 23 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 * Create a [LibraryContext] which is prepared to analyze [library]. | 38 * Create a [LibraryContext] which is prepared to analyze [library]. |
| 38 */ | 39 */ |
| 39 factory LibraryContext.forSingleLibrary( | 40 factory LibraryContext.forSingleLibrary( |
| 40 FileState library, | 41 FileState library, |
| 41 PerformanceLog logger, | 42 PerformanceLog logger, |
| 42 PackageBundle sdkBundle, | 43 PackageBundle sdkBundle, |
| 43 ByteStore byteStore, | 44 ByteStore byteStore, |
| 44 AnalysisOptions options, | 45 AnalysisOptions options, |
| 45 DeclaredVariables declaredVariables, | 46 DeclaredVariables declaredVariables, |
| 46 SourceFactory sourceFactory, | 47 SourceFactory sourceFactory, |
| 47 FileSystemState fsState) { | 48 FileTracker fileTracker) { |
| 48 return logger.run('Create library context', () { | 49 return logger.run('Create library context', () { |
| 49 Map<String, FileState> libraries = <String, FileState>{}; | 50 Map<String, FileState> libraries = <String, FileState>{}; |
| 50 SummaryDataStore store = new SummaryDataStore(const <String>[]); | 51 SummaryDataStore store = new SummaryDataStore(const <String>[]); |
| 51 | 52 |
| 52 if (sdkBundle != null) { | 53 if (sdkBundle != null) { |
| 53 store.addBundle(null, sdkBundle); | 54 store.addBundle(null, sdkBundle); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void appendLibraryFiles(FileState library) { | 57 void appendLibraryFiles(FileState library) { |
| 57 if (!libraries.containsKey(library.uriStr)) { | 58 if (!libraries.containsKey(library.uriStr)) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 linkedLibraries.forEach((uri, linkedBuilder) { | 114 linkedLibraries.forEach((uri, linkedBuilder) { |
| 114 FileState library = libraries[uri]; | 115 FileState library = libraries[uri]; |
| 115 String key = '${library.transitiveSignature}.linked'; | 116 String key = '${library.transitiveSignature}.linked'; |
| 116 List<int> bytes = linkedBuilder.toBuffer(); | 117 List<int> bytes = linkedBuilder.toBuffer(); |
| 117 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); | 118 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); |
| 118 store.addLinkedLibrary(uri, linked); | 119 store.addLinkedLibrary(uri, linked); |
| 119 byteStore.put(key, bytes); | 120 byteStore.put(key, bytes); |
| 120 }); | 121 }); |
| 121 | 122 |
| 122 var analysisContext = _createAnalysisContext( | 123 var analysisContext = _createAnalysisContext( |
| 123 options, declaredVariables, sourceFactory, fsState, store); | 124 options, declaredVariables, sourceFactory, fileTracker, store); |
| 124 | 125 |
| 125 return new LibraryContext._(analysisContext); | 126 return new LibraryContext._(analysisContext); |
| 126 }); | 127 }); |
| 127 } | 128 } |
| 128 | 129 |
| 129 LibraryContext._(this._analysisContext); | 130 LibraryContext._(this._analysisContext); |
| 130 | 131 |
| 131 /** | 132 /** |
| 132 * Computes a [CompilationUnitElement] for the given library/unit pair. | 133 * Computes a [CompilationUnitElement] for the given library/unit pair. |
| 133 */ | 134 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 155 CompilationUnit resolvedUnit = | 156 CompilationUnit resolvedUnit = |
| 156 _analysisContext.resolveCompilationUnit2(unitSource, librarySource); | 157 _analysisContext.resolveCompilationUnit2(unitSource, librarySource); |
| 157 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource); | 158 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource); |
| 158 return new ResolutionResult(resolvedUnit, errors); | 159 return new ResolutionResult(resolvedUnit, errors); |
| 159 } | 160 } |
| 160 | 161 |
| 161 static AnalysisContext _createAnalysisContext( | 162 static AnalysisContext _createAnalysisContext( |
| 162 AnalysisOptions _analysisOptions, | 163 AnalysisOptions _analysisOptions, |
| 163 DeclaredVariables declaredVariables, | 164 DeclaredVariables declaredVariables, |
| 164 SourceFactory _sourceFactory, | 165 SourceFactory _sourceFactory, |
| 165 FileSystemState _fsState, | 166 FileTracker fileTracker, |
| 166 SummaryDataStore store) { | 167 SummaryDataStore store) { |
| 167 AnalysisContextImpl analysisContext = | 168 AnalysisContextImpl analysisContext = |
| 168 AnalysisEngine.instance.createAnalysisContext(); | 169 AnalysisEngine.instance.createAnalysisContext(); |
| 169 analysisContext.useSdkCachePartition = false; | 170 analysisContext.useSdkCachePartition = false; |
| 170 analysisContext.analysisOptions = _analysisOptions; | 171 analysisContext.analysisOptions = _analysisOptions; |
| 171 analysisContext.declaredVariables.addAll(declaredVariables); | 172 analysisContext.declaredVariables.addAll(declaredVariables); |
| 172 analysisContext.sourceFactory = _sourceFactory.clone(); | 173 analysisContext.sourceFactory = _sourceFactory.clone(); |
| 173 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); | 174 analysisContext.contentCache = new _ContentCacheWrapper(fileTracker); |
| 174 analysisContext.resultProvider = | 175 analysisContext.resultProvider = |
| 175 new InputPackagesResultProvider(analysisContext, store); | 176 new InputPackagesResultProvider(analysisContext, store); |
| 176 return analysisContext; | 177 return analysisContext; |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 | 180 |
| 180 /** | 181 /** |
| 181 * Container object holding the result of a call to | 182 * Container object holding the result of a call to |
| 182 * [LibraryContext.resolveUnit]. | 183 * [LibraryContext.resolveUnit]. |
| 183 */ | 184 */ |
| 184 class ResolutionResult { | 185 class ResolutionResult { |
| 185 final CompilationUnit resolvedUnit; | 186 final CompilationUnit resolvedUnit; |
| 186 final List<AnalysisError> errors; | 187 final List<AnalysisError> errors; |
| 187 | 188 |
| 188 ResolutionResult(this.resolvedUnit, this.errors); | 189 ResolutionResult(this.resolvedUnit, this.errors); |
| 189 } | 190 } |
| 190 | 191 |
| 191 /** | 192 /** |
| 192 * [ContentCache] wrapper around [FileContentOverlay]. | 193 * [ContentCache] wrapper around [FileContentOverlay]. |
| 193 */ | 194 */ |
| 194 class _ContentCacheWrapper implements ContentCache { | 195 class _ContentCacheWrapper implements ContentCache { |
| 195 final FileSystemState fsState; | 196 final FileTracker fileTracker; |
| 196 | 197 |
| 197 _ContentCacheWrapper(this.fsState); | 198 _ContentCacheWrapper(this.fileTracker); |
| 198 | 199 |
| 199 @override | 200 @override |
| 200 void accept(ContentCacheVisitor visitor) { | 201 void accept(ContentCacheVisitor visitor) { |
| 201 throw new UnimplementedError(); | 202 throw new UnimplementedError(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 @override | 205 @override |
| 205 String getContents(Source source) { | 206 String getContents(Source source) { |
| 206 return _getFileForSource(source).content; | 207 return _getFileForSource(source).content; |
| 207 } | 208 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 222 return _getFileForSource(source).exists ? 0 : -1; | 223 return _getFileForSource(source).exists ? 0 : -1; |
| 223 } | 224 } |
| 224 | 225 |
| 225 @override | 226 @override |
| 226 String setContents(Source source, String contents) { | 227 String setContents(Source source, String contents) { |
| 227 throw new UnimplementedError(); | 228 throw new UnimplementedError(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 FileState _getFileForSource(Source source) { | 231 FileState _getFileForSource(Source source) { |
| 231 String path = source.fullName; | 232 String path = source.fullName; |
| 232 return fsState.getFileForPath(path); | 233 return fileTracker.fsState.getFileForPath(path); |
| 233 } | 234 } |
| 234 } | 235 } |
| OLD | NEW |