| 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/context/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 } | 480 } |
| 481 | 481 |
| 482 /** | 482 /** |
| 483 * Notify the driver that the client is going to stop using it. | 483 * Notify the driver that the client is going to stop using it. |
| 484 */ | 484 */ |
| 485 void dispose() { | 485 void dispose() { |
| 486 _scheduler._remove(this); | 486 _scheduler._remove(this); |
| 487 } | 487 } |
| 488 | 488 |
| 489 /** | 489 /** |
| 490 * Return a [Future] that completes with the [ErrorsResult] for the Dart |
| 491 * file with the given [path]. If the file is not a Dart file or cannot |
| 492 * be analyzed, the [Future] completes with `null`. |
| 493 * |
| 494 * The [path] must be absolute and normalized. |
| 495 * |
| 496 * This method does not use analysis priorities, and must not be used in |
| 497 * interactive analysis, such as Analysis Server or its plugins. |
| 498 */ |
| 499 Future<ErrorsResult> getErrors(String path) async { |
| 500 // Ask the analysis result without unit, so return cached errors. |
| 501 // If no cached analysis result, it will be computed. |
| 502 AnalysisResult analysisResult = _computeAnalysisResult(path); |
| 503 |
| 504 // If not computed yet, because a part file without a known library, |
| 505 // we have to compute the full analysis result, with the unit. |
| 506 analysisResult ??= await getResult(path); |
| 507 if (analysisResult == null) { |
| 508 return null; |
| 509 } |
| 510 |
| 511 return new ErrorsResult( |
| 512 path, |
| 513 analysisResult.uri, |
| 514 analysisResult.contentHash, |
| 515 analysisResult.lineInfo, |
| 516 analysisResult.errors); |
| 517 } |
| 518 |
| 519 /** |
| 490 * Return a [Future] that completes with the list of added files that | 520 * Return a [Future] that completes with the list of added files that |
| 491 * reference the given external [name]. | 521 * reference the given external [name]. |
| 492 */ | 522 */ |
| 493 Future<List<String>> getFilesReferencingName(String name) { | 523 Future<List<String>> getFilesReferencingName(String name) { |
| 494 var task = new _FilesReferencingNameTask(this, name); | 524 var task = new _FilesReferencingNameTask(this, name); |
| 495 _referencingNameTasks.add(task); | 525 _referencingNameTasks.add(task); |
| 496 _statusSupport.transitionToAnalyzing(); | 526 _statusSupport.transitionToAnalyzing(); |
| 497 _scheduler._notify(this); | 527 _scheduler._notify(this); |
| 498 return task.completer.future; | 528 return task.completer.future; |
| 499 } | 529 } |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 this.exists, | 1413 this.exists, |
| 1384 this.content, | 1414 this.content, |
| 1385 this.contentHash, | 1415 this.contentHash, |
| 1386 this.lineInfo, | 1416 this.lineInfo, |
| 1387 this.unit, | 1417 this.unit, |
| 1388 this.errors, | 1418 this.errors, |
| 1389 this._index); | 1419 this._index); |
| 1390 } | 1420 } |
| 1391 | 1421 |
| 1392 /** | 1422 /** |
| 1423 * The errors in a single file. |
| 1424 * |
| 1425 * These results are self-consistent, i.e. [content], [contentHash], [errors] |
| 1426 * correspond to each other. But none of the results is guaranteed to be |
| 1427 * consistent with the state of the files. |
| 1428 */ |
| 1429 class ErrorsResult { |
| 1430 /** |
| 1431 * The path of the parsed file, absolute and normalized. |
| 1432 */ |
| 1433 final String path; |
| 1434 |
| 1435 /** |
| 1436 * The URI of the file that corresponded to the [path]. |
| 1437 */ |
| 1438 final Uri uri; |
| 1439 |
| 1440 /** |
| 1441 * The MD5 hash of the [content]. |
| 1442 */ |
| 1443 final String contentHash; |
| 1444 |
| 1445 /** |
| 1446 * Information about lines in the [content]. |
| 1447 */ |
| 1448 final LineInfo lineInfo; |
| 1449 |
| 1450 /** |
| 1451 * The full list of computed analysis errors, both syntactic and semantic. |
| 1452 */ |
| 1453 final List<AnalysisError> errors; |
| 1454 |
| 1455 ErrorsResult( |
| 1456 this.path, this.uri, this.contentHash, this.lineInfo, this.errors); |
| 1457 } |
| 1458 |
| 1459 /** |
| 1393 * Exception that happened during analysis. | 1460 * Exception that happened during analysis. |
| 1394 */ | 1461 */ |
| 1395 class ExceptionResult { | 1462 class ExceptionResult { |
| 1396 /** | 1463 /** |
| 1397 * The path of the file being analyzed when the [exception] happened. | 1464 * The path of the file being analyzed when the [exception] happened. |
| 1398 * | 1465 * |
| 1399 * Absolute and normalized. | 1466 * Absolute and normalized. |
| 1400 */ | 1467 */ |
| 1401 final String path; | 1468 final String path; |
| 1402 | 1469 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 libraryDeclarations.add(new TopLevelDeclarationInSource( | 1762 libraryDeclarations.add(new TopLevelDeclarationInSource( |
| 1696 file.source, declaration, isExported)); | 1763 file.source, declaration, isExported)); |
| 1697 } | 1764 } |
| 1698 } | 1765 } |
| 1699 } | 1766 } |
| 1700 | 1767 |
| 1701 // We're not done yet. | 1768 // We're not done yet. |
| 1702 return false; | 1769 return false; |
| 1703 } | 1770 } |
| 1704 } | 1771 } |
| OLD | NEW |