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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * The list of files this library file references as parts. | 133 * The list of files this library file references as parts. |
134 */ | 134 */ |
135 List<FileState> get partedFiles => _partedFiles; | 135 List<FileState> get partedFiles => _partedFiles; |
136 | 136 |
137 /** | 137 /** |
138 * The [UnlinkedUnit] of the file. | 138 * The [UnlinkedUnit] of the file. |
139 */ | 139 */ |
140 UnlinkedUnit get unlinked => _unlinked; | 140 UnlinkedUnit get unlinked => _unlinked; |
141 | 141 |
142 /** | 142 /** |
| 143 * Return a new parsed unresolved [CompilationUnit]. |
| 144 */ |
| 145 CompilationUnit parse(AnalysisErrorListener errorListener) { |
| 146 AnalysisOptions analysisOptions = _fsState._analysisOptions; |
| 147 |
| 148 CharSequenceReader reader = new CharSequenceReader(content); |
| 149 Scanner scanner = new Scanner(source, reader, errorListener); |
| 150 scanner.scanGenericMethodComments = analysisOptions.strongMode; |
| 151 Token token = scanner.tokenize(); |
| 152 LineInfo lineInfo = new LineInfo(scanner.lineStarts); |
| 153 |
| 154 Parser parser = new Parser(source, errorListener); |
| 155 parser.parseGenericMethodComments = analysisOptions.strongMode; |
| 156 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 157 unit.lineInfo = lineInfo; |
| 158 return unit; |
| 159 } |
| 160 |
| 161 /** |
143 * Read the file content and ensure that all of the file properties are | 162 * Read the file content and ensure that all of the file properties are |
144 * consistent with the read content, including API signature. | 163 * consistent with the read content, including API signature. |
145 * | 164 * |
146 * Return `true` if the API signature changed since the last refresh. | 165 * Return `true` if the API signature changed since the last refresh. |
147 */ | 166 */ |
148 bool refresh() { | 167 bool refresh() { |
149 // Read the content. | 168 // Read the content. |
150 try { | 169 try { |
151 _content = _fsState._contentOverlay[path]; | 170 _content = _fsState._contentOverlay[path]; |
152 _content ??= _fsState._resourceProvider.getFile(path).readAsStringSync(); | 171 _content ??= _fsState._resourceProvider.getFile(path).readAsStringSync(); |
(...skipping 22 matching lines...) Expand all Loading... |
175 signature.addUint32List(_fsState._salt); | 194 signature.addUint32List(_fsState._salt); |
176 signature.addBytes(contentBytes); | 195 signature.addBytes(contentBytes); |
177 unlinkedKey = '${signature.toHex()}.unlinked'; | 196 unlinkedKey = '${signature.toHex()}.unlinked'; |
178 } | 197 } |
179 | 198 |
180 // Prepare bytes of the unlinked bundle - existing or new. | 199 // Prepare bytes of the unlinked bundle - existing or new. |
181 List<int> bytes; | 200 List<int> bytes; |
182 { | 201 { |
183 bytes = _fsState._byteStore.get(unlinkedKey); | 202 bytes = _fsState._byteStore.get(unlinkedKey); |
184 if (bytes == null) { | 203 if (bytes == null) { |
185 CompilationUnit unit = | 204 CompilationUnit unit = parse(AnalysisErrorListener.NULL_LISTENER); |
186 _parse(source, _content, _fsState._analysisOptions); | |
187 _fsState._logger.run('Create unlinked for $path', () { | 205 _fsState._logger.run('Create unlinked for $path', () { |
188 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); | 206 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); |
189 bytes = unlinkedUnit.toBuffer(); | 207 bytes = unlinkedUnit.toBuffer(); |
190 _fsState._byteStore.put(unlinkedKey, bytes); | 208 _fsState._byteStore.put(unlinkedKey, bytes); |
191 }); | 209 }); |
192 } | 210 } |
193 } | 211 } |
194 | 212 |
195 // Read the unlinked bundle. | 213 // Read the unlinked bundle. |
196 _unlinked = new UnlinkedUnit.fromBuffer(bytes); | 214 _unlinked = new UnlinkedUnit.fromBuffer(bytes); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (a[i] != b[i]) { | 289 if (a[i] != b[i]) { |
272 return false; | 290 return false; |
273 } | 291 } |
274 } | 292 } |
275 return true; | 293 return true; |
276 } | 294 } |
277 | 295 |
278 static bool _isDartUri(String uri) { | 296 static bool _isDartUri(String uri) { |
279 return uri.startsWith('dart:'); | 297 return uri.startsWith('dart:'); |
280 } | 298 } |
281 | |
282 /** | |
283 * Return the parsed unresolved [CompilationUnit] for the given [content]. | |
284 */ | |
285 static CompilationUnit _parse( | |
286 Source source, String content, AnalysisOptions analysisOptions) { | |
287 AnalysisErrorListener errorListener = AnalysisErrorListener.NULL_LISTENER; | |
288 | |
289 CharSequenceReader reader = new CharSequenceReader(content); | |
290 Scanner scanner = new Scanner(source, reader, errorListener); | |
291 scanner.scanGenericMethodComments = analysisOptions.strongMode; | |
292 Token token = scanner.tokenize(); | |
293 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | |
294 | |
295 Parser parser = new Parser(source, errorListener); | |
296 parser.parseGenericMethodComments = analysisOptions.strongMode; | |
297 CompilationUnit unit = parser.parseCompilationUnit(token); | |
298 unit.lineInfo = lineInfo; | |
299 return unit; | |
300 } | |
301 } | 299 } |
302 | 300 |
303 /** | 301 /** |
304 * Information about known file system state. | 302 * Information about known file system state. |
305 */ | 303 */ |
306 class FileSystemState { | 304 class FileSystemState { |
307 final PerformanceLog _logger; | 305 final PerformanceLog _logger; |
308 final ResourceProvider _resourceProvider; | 306 final ResourceProvider _resourceProvider; |
309 final ByteStore _byteStore; | 307 final ByteStore _byteStore; |
310 final FileContentOverlay _contentOverlay; | 308 final FileContentOverlay _contentOverlay; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 FileState canonicalFile = getFileForPath(path); | 398 FileState canonicalFile = getFileForPath(path); |
401 List<FileState> allFiles = _pathToFiles[path].toList(); | 399 List<FileState> allFiles = _pathToFiles[path].toList(); |
402 if (allFiles.length == 1) { | 400 if (allFiles.length == 1) { |
403 return allFiles; | 401 return allFiles; |
404 } | 402 } |
405 return allFiles | 403 return allFiles |
406 ..remove(canonicalFile) | 404 ..remove(canonicalFile) |
407 ..insert(0, canonicalFile); | 405 ..insert(0, canonicalFile); |
408 } | 406 } |
409 } | 407 } |
OLD | NEW |