| 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' |
| 8 show CompilationUnitElement, LibraryElement; |
| 8 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 9 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 11 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 11 import 'package:analyzer/src/dart/analysis/driver.dart'; | 12 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 13 import 'package:analyzer/src/dart/analysis/file_state.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'; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 linkedLibraries.forEach((uri, linkedBuilder) { | 125 linkedLibraries.forEach((uri, linkedBuilder) { |
| 125 FileState library = libraries[uri]; | 126 FileState library = libraries[uri]; |
| 126 String key = '${library.transitiveSignature}.linked'; | 127 String key = '${library.transitiveSignature}.linked'; |
| 127 List<int> bytes = linkedBuilder.toBuffer(); | 128 List<int> bytes = linkedBuilder.toBuffer(); |
| 128 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); | 129 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); |
| 129 store.addLinkedLibrary(uri, linked); | 130 store.addLinkedLibrary(uri, linked); |
| 130 byteStore.put(key, bytes); | 131 byteStore.put(key, bytes); |
| 131 }); | 132 }); |
| 132 | 133 |
| 133 var analysisContext = _createAnalysisContext( | 134 AnalysisContextImpl analysisContext = _createAnalysisContext( |
| 134 options, declaredVariables, sourceFactory, fsState, store); | 135 options, declaredVariables, sourceFactory, store); |
| 136 analysisContext.contentCache = new _ContentCacheWrapper(fsState); |
| 135 | 137 |
| 136 return new LibraryContext._(store, analysisContext); | 138 return new LibraryContext._(store, analysisContext); |
| 137 }); | 139 }); |
| 138 } | 140 } |
| 139 | 141 |
| 140 LibraryContext._(this.store, this._analysisContext); | 142 LibraryContext._(this.store, this._analysisContext); |
| 141 | 143 |
| 142 /** | 144 /** |
| 143 * Computes a [CompilationUnitElement] for the given library/unit pair. | 145 * Computes a [CompilationUnitElement] for the given library/unit pair. |
| 144 */ | 146 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 * Computes a resolved [CompilationUnit] and a list of [AnalysisError]s for | 164 * Computes a resolved [CompilationUnit] and a list of [AnalysisError]s for |
| 163 * the given library/unit pair. | 165 * the given library/unit pair. |
| 164 */ | 166 */ |
| 165 ResolutionResult resolveUnit(Source librarySource, Source unitSource) { | 167 ResolutionResult resolveUnit(Source librarySource, Source unitSource) { |
| 166 CompilationUnit resolvedUnit = | 168 CompilationUnit resolvedUnit = |
| 167 _analysisContext.resolveCompilationUnit2(unitSource, librarySource); | 169 _analysisContext.resolveCompilationUnit2(unitSource, librarySource); |
| 168 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource); | 170 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource); |
| 169 return new ResolutionResult(resolvedUnit, errors); | 171 return new ResolutionResult(resolvedUnit, errors); |
| 170 } | 172 } |
| 171 | 173 |
| 172 static AnalysisContext _createAnalysisContext( | 174 /** |
| 173 AnalysisOptions _analysisOptions, | 175 * Resynthesize the [LibraryElement] from the given [store]. |
| 176 */ |
| 177 static LibraryElement resynthesizeLibraryElement( |
| 178 AnalysisOptions analysisOptions, |
| 174 DeclaredVariables declaredVariables, | 179 DeclaredVariables declaredVariables, |
| 175 SourceFactory _sourceFactory, | 180 SourceFactory sourceFactory, |
| 176 FileSystemState fileSystemState, | 181 SummaryDataStore store, |
| 182 String uri) { |
| 183 AnalysisContextImpl analysisContext = _createAnalysisContext( |
| 184 analysisOptions, declaredVariables, sourceFactory, store); |
| 185 try { |
| 186 return new StoreBasedSummaryResynthesizer( |
| 187 analysisContext, sourceFactory, analysisOptions.strongMode, store) |
| 188 .getLibraryElement(uri); |
| 189 } finally { |
| 190 analysisContext.dispose(); |
| 191 } |
| 192 } |
| 193 |
| 194 static AnalysisContextImpl _createAnalysisContext( |
| 195 AnalysisOptions analysisOptions, |
| 196 DeclaredVariables declaredVariables, |
| 197 SourceFactory sourceFactory, |
| 177 SummaryDataStore store) { | 198 SummaryDataStore store) { |
| 178 AnalysisContextImpl analysisContext = | 199 AnalysisContextImpl analysisContext = |
| 179 AnalysisEngine.instance.createAnalysisContext(); | 200 AnalysisEngine.instance.createAnalysisContext(); |
| 180 analysisContext.useSdkCachePartition = false; | 201 analysisContext.useSdkCachePartition = false; |
| 181 analysisContext.analysisOptions = _analysisOptions; | 202 analysisContext.analysisOptions = analysisOptions; |
| 182 analysisContext.declaredVariables.addAll(declaredVariables); | 203 analysisContext.declaredVariables.addAll(declaredVariables); |
| 183 analysisContext.sourceFactory = _sourceFactory.clone(); | 204 analysisContext.sourceFactory = sourceFactory.clone(); |
| 184 analysisContext.contentCache = new _ContentCacheWrapper(fileSystemState); | |
| 185 analysisContext.resultProvider = | 205 analysisContext.resultProvider = |
| 186 new InputPackagesResultProvider(analysisContext, store); | 206 new InputPackagesResultProvider(analysisContext, store); |
| 187 return analysisContext; | 207 return analysisContext; |
| 188 } | 208 } |
| 189 } | 209 } |
| 190 | 210 |
| 191 /** | 211 /** |
| 192 * Container object holding the result of a call to | 212 * Container object holding the result of a call to |
| 193 * [LibraryContext.resolveUnit]. | 213 * [LibraryContext.resolveUnit]. |
| 194 */ | 214 */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 @override | 260 @override |
| 241 String setContents(Source source, String contents) { | 261 String setContents(Source source, String contents) { |
| 242 throw new UnimplementedError(); | 262 throw new UnimplementedError(); |
| 243 } | 263 } |
| 244 | 264 |
| 245 FileState _getFileForSource(Source source) { | 265 FileState _getFileForSource(Source source) { |
| 246 String path = source.fullName; | 266 String path = source.fullName; |
| 247 return fsState.getFileForPath(path); | 267 return fsState.getFileForPath(path); |
| 248 } | 268 } |
| 249 } | 269 } |
| OLD | NEW |