Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2908543002: Add result interfaces used by AnalysisSession (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/context_root.dart'; 9 import 'package:analyzer/context/context_root.dart';
10 import 'package:analyzer/context/declared_variables.dart'; 10 import 'package:analyzer/context/declared_variables.dart';
11 import 'package:analyzer/dart/analysis/results.dart' as results;
11 import 'package:analyzer/dart/ast/ast.dart'; 12 import 'package:analyzer/dart/ast/ast.dart';
12 import 'package:analyzer/dart/element/element.dart' 13 import 'package:analyzer/dart/element/element.dart'
13 show CompilationUnitElement, LibraryElement; 14 show CompilationUnitElement, LibraryElement;
14 import 'package:analyzer/error/error.dart'; 15 import 'package:analyzer/error/error.dart';
15 import 'package:analyzer/error/listener.dart'; 16 import 'package:analyzer/error/listener.dart';
16 import 'package:analyzer/exception/exception.dart'; 17 import 'package:analyzer/exception/exception.dart';
17 import 'package:analyzer/file_system/file_system.dart'; 18 import 'package:analyzer/file_system/file_system.dart';
18 import 'package:analyzer/src/dart/analysis/file_state.dart'; 19 import 'package:analyzer/src/dart/analysis/file_state.dart';
19 import 'package:analyzer/src/dart/analysis/file_tracker.dart'; 20 import 'package:analyzer/src/dart/analysis/file_tracker.dart';
20 import 'package:analyzer/src/dart/analysis/index.dart'; 21 import 'package:analyzer/src/dart/analysis/index.dart';
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 FileState library = file.library ?? file; 1052 FileState library = file.library ?? file;
1052 1053
1053 // Create the AnalysisContext to resynthesize elements in. 1054 // Create the AnalysisContext to resynthesize elements in.
1054 LibraryContext libraryContext = _createLibraryContext(library); 1055 LibraryContext libraryContext = _createLibraryContext(library);
1055 1056
1056 // Resynthesize the CompilationUnitElement in the context. 1057 // Resynthesize the CompilationUnitElement in the context.
1057 try { 1058 try {
1058 CompilationUnitElement element = 1059 CompilationUnitElement element =
1059 libraryContext.computeUnitElement(library.source, file.source); 1060 libraryContext.computeUnitElement(library.source, file.source);
1060 String signature = library.transitiveSignature; 1061 String signature = library.transitiveSignature;
1061 return new UnitElementResult(path, signature, element); 1062 return new UnitElementResult(path, file.uri, signature, element);
1062 } finally { 1063 } finally {
1063 libraryContext.dispose(); 1064 libraryContext.dispose();
1064 } 1065 }
1065 } 1066 }
1066 1067
1067 String _computeUnitElementSignature(String path) { 1068 String _computeUnitElementSignature(String path) {
1068 FileState file = _fsState.getFileForPath(path); 1069 FileState file = _fsState.getFileForPath(path);
1069 FileState library = file.library ?? file; 1070 FileState library = file.library ?? file;
1070 return library.transitiveSignature; 1071 return library.transitiveSignature;
1071 } 1072 }
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 * The result of analyzing of a single file. 1584 * The result of analyzing of a single file.
1584 * 1585 *
1585 * These results are self-consistent, i.e. [content], [contentHash], the 1586 * These results are self-consistent, i.e. [content], [contentHash], the
1586 * resolved [unit] correspond to each other. All referenced elements, even 1587 * resolved [unit] correspond to each other. All referenced elements, even
1587 * external ones, are also self-consistent. But none of the results is 1588 * external ones, are also self-consistent. But none of the results is
1588 * guaranteed to be consistent with the state of the files. 1589 * guaranteed to be consistent with the state of the files.
1589 * 1590 *
1590 * Every result is independent, and is not guaranteed to be consistent with 1591 * Every result is independent, and is not guaranteed to be consistent with
1591 * any previously returned result, even inside of the same library. 1592 * any previously returned result, even inside of the same library.
1592 */ 1593 */
1593 class AnalysisResult { 1594 class AnalysisResult implements results.ResolveResult {
1594 static final _UNCHANGED = new AnalysisResult( 1595 static final _UNCHANGED = new AnalysisResult(
1595 null, null, null, null, null, null, null, null, null, null, null); 1596 null, null, null, null, null, null, null, null, null, null, null);
1596 1597
1597 /** 1598 /**
1598 * The [AnalysisDriver] that produced this result. 1599 * The [AnalysisDriver] that produced this result.
1599 */ 1600 */
1600 final AnalysisDriver driver; 1601 final AnalysisDriver driver;
1601 1602
1602 /** 1603 /**
1603 * The [SourceFactory] with which the file was analyzed. 1604 * The [SourceFactory] with which the file was analyzed.
1604 */ 1605 */
1605 final SourceFactory sourceFactory; 1606 final SourceFactory sourceFactory;
1606 1607
1607 /** 1608 @override
1608 * The path of the analysed file, absolute and normalized. 1609 final String filePath;
1609 */
1610 final String path;
1611 1610
1612 /** 1611 @override
1613 * The URI of the file that corresponded to the [path] in the used
1614 * [SourceFactory] at some point. Is it not guaranteed to be still consistent
1615 * to the [path], and provided as FYI.
1616 */
1617 final Uri uri; 1612 final Uri uri;
1618 1613
1619 /** 1614 /**
1620 * Return `true` if the file exists. 1615 * Return `true` if the file exists.
1621 */ 1616 */
1622 final bool exists; 1617 final bool exists;
1623 1618
1624 /** 1619 @override
1625 * The content of the file that was scanned, parsed and resolved.
1626 */
1627 final String content; 1620 final String content;
1628 1621
1629 /** 1622 @override
1630 * Information about lines in the [content].
1631 */
1632 final LineInfo lineInfo; 1623 final LineInfo lineInfo;
1633 1624
1634 /** 1625 /**
1635 * The signature of the result based on the content of the file, and the 1626 * The signature of the result based on the content of the file, and the
1636 * transitive closure of files imported and exported by the library of 1627 * transitive closure of files imported and exported by the library of
1637 * the requested file. 1628 * the requested file.
1638 */ 1629 */
1639 final String _signature; 1630 final String _signature;
1640 1631
1641 /** 1632 @override
1642 * The fully resolved compilation unit for the [content].
1643 */
1644 final CompilationUnit unit; 1633 final CompilationUnit unit;
1645 1634
1646 /** 1635 @override
1647 * The full list of computed analysis errors, both syntactic and semantic.
1648 */
1649 final List<AnalysisError> errors; 1636 final List<AnalysisError> errors;
1650 1637
1651 /** 1638 /**
1652 * The index of the unit. 1639 * The index of the unit.
1653 */ 1640 */
1654 final AnalysisDriverUnitIndex _index; 1641 final AnalysisDriverUnitIndex _index;
1655 1642
1656 AnalysisResult( 1643 AnalysisResult(
1657 this.driver, 1644 this.driver,
1658 this.sourceFactory, 1645 this.sourceFactory,
1659 this.path, 1646 this.filePath,
1660 this.uri, 1647 this.uri,
1661 this.exists, 1648 this.exists,
1662 this.content, 1649 this.content,
1663 this.lineInfo, 1650 this.lineInfo,
1664 this._signature, 1651 this._signature,
1665 this.unit, 1652 this.unit,
1666 this.errors, 1653 this.errors,
1667 this._index); 1654 this._index);
1655
1656 /**
1657 * The path of the analysed file, absolute and normalized.
1658 */
1659 //@deprecated
1660 String get path => filePath;
1661
1662 @override
1663 results.ResultState get state =>
1664 exists ? results.ResultState.VALID : results.ResultState.NOT_A_FILE;
1668 } 1665 }
1669 1666
1670 /** 1667 /**
1671 * An object that watches for the creation and removal of analysis drivers. 1668 * An object that watches for the creation and removal of analysis drivers.
1672 * 1669 *
1673 * Clients may not extend, implement or mix-in this class. 1670 * Clients may not extend, implement or mix-in this class.
1674 */ 1671 */
1675 abstract class DriverWatcher { 1672 abstract class DriverWatcher {
1676 /** 1673 /**
1677 * The context manager has just added the given analysis [driver]. This method 1674 * The context manager has just added the given analysis [driver]. This method
1678 * must be called before the driver has been allowed to perform any analysis. 1675 * must be called before the driver has been allowed to perform any analysis.
1679 */ 1676 */
1680 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot); 1677 void addedDriver(AnalysisDriver driver, ContextRoot contextRoot);
1681 1678
1682 /** 1679 /**
1683 * The context manager has just removed the given analysis [driver]. 1680 * The context manager has just removed the given analysis [driver].
1684 */ 1681 */
1685 void removedDriver(AnalysisDriver driver); 1682 void removedDriver(AnalysisDriver driver);
1686 } 1683 }
1687 1684
1688 /** 1685 /**
1689 * The errors in a single file. 1686 * The errors in a single file.
1690 * 1687 *
1691 * These results are self-consistent, i.e. [content], [contentHash], [errors] 1688 * These results are self-consistent, i.e. [content], [contentHash], [errors]
1692 * correspond to each other. But none of the results is guaranteed to be 1689 * correspond to each other. But none of the results is guaranteed to be
1693 * consistent with the state of the files. 1690 * consistent with the state of the files.
1694 */ 1691 */
1695 class ErrorsResult { 1692 class ErrorsResult implements results.ErrorsResult {
1693 @override
1694 final String filePath;
1695
1696 @override
1697 final Uri uri;
1698
1699 @override
1700 final LineInfo lineInfo;
1701
1702 @override
1703 final List<AnalysisError> errors;
1704
1705 ErrorsResult(this.filePath, this.uri, this.lineInfo, this.errors);
1706
1696 /** 1707 /**
1697 * The path of the parsed file, absolute and normalized. 1708 * The path of the parsed file, absolute and normalized.
1698 */ 1709 */
1699 final String path; 1710 //@deprecated
1711 String get path => filePath;
1700 1712
1701 /** 1713 @override
1702 * The URI of the file that corresponded to the [path]. 1714 results.ResultState get state => results.ResultState.VALID;
1703 */
1704 final Uri uri;
1705
1706 /**
1707 * Information about lines in the [content].
1708 */
1709 final LineInfo lineInfo;
1710
1711 /**
1712 * The full list of computed analysis errors, both syntactic and semantic.
1713 */
1714 final List<AnalysisError> errors;
1715
1716 ErrorsResult(this.path, this.uri, this.lineInfo, this.errors);
1717 } 1715 }
1718 1716
1719 /** 1717 /**
1720 * Exception that happened during analysis. 1718 * Exception that happened during analysis.
1721 */ 1719 */
1722 class ExceptionResult { 1720 class ExceptionResult {
1723 /** 1721 /**
1724 * The path of the file being analyzed when the [exception] happened. 1722 * The path of the file being analyzed when the [exception] happened.
1725 * 1723 *
1726 * Absolute and normalized. 1724 * Absolute and normalized.
(...skipping 16 matching lines...) Expand all
1743 ExceptionResult(this.path, this.exception, this.contextKey); 1741 ExceptionResult(this.path, this.exception, this.contextKey);
1744 } 1742 }
1745 1743
1746 /** 1744 /**
1747 * The result of parsing of a single file. 1745 * The result of parsing of a single file.
1748 * 1746 *
1749 * These results are self-consistent, i.e. [content], [contentHash], the 1747 * These results are self-consistent, i.e. [content], [contentHash], the
1750 * resolved [unit] correspond to each other. But none of the results is 1748 * resolved [unit] correspond to each other. But none of the results is
1751 * guaranteed to be consistent with the state of the files. 1749 * guaranteed to be consistent with the state of the files.
1752 */ 1750 */
1753 class ParseResult { 1751 class ParseResult implements results.ParseResult {
1752 @override
1753 final String filePath;
1754
1755 @override
1756 final Uri uri;
1757
1758 @override
1759 final String content;
1760
1761 @override
1762 final LineInfo lineInfo;
1763
1764 @override
1765 final CompilationUnit unit;
1766
1767 @override
1768 final List<AnalysisError> errors;
1769
1770 ParseResult(this.filePath, this.uri, this.content, this.lineInfo, this.unit,
1771 this.errors);
1772
1754 /** 1773 /**
1755 * The path of the parsed file, absolute and normalized. 1774 * The path of the parsed file, absolute and normalized.
1756 */ 1775 */
1757 final String path; 1776 //@deprecated
1777 String get path => filePath;
1758 1778
1759 /** 1779 @override
1760 * The URI of the file that corresponded to the [path]. 1780 results.ResultState get state => results.ResultState.VALID;
1761 */
1762 final Uri uri;
1763
1764 /**
1765 * The content of the file that was scanned and parsed.
1766 */
1767 final String content;
1768
1769 /**
1770 * Information about lines in the [content].
1771 */
1772 final LineInfo lineInfo;
1773
1774 /**
1775 * The parsed, unresolved compilation unit for the [content].
1776 */
1777 final CompilationUnit unit;
1778
1779 /**
1780 * The scanning and parsing errors.
1781 */
1782 final List<AnalysisError> errors;
1783
1784 ParseResult(
1785 this.path, this.uri, this.content, this.lineInfo, this.unit, this.errors);
1786 } 1781 }
1787 1782
1788 /** 1783 /**
1789 * The result with the [CompilationUnitElement] of a single file. 1784 * The result with the [CompilationUnitElement] of a single file.
1790 * 1785 *
1791 * These results are self-consistent, i.e. all elements and types accessible 1786 * These results are self-consistent, i.e. all elements and types accessible
1792 * through [element], including defined in other files, correspond to each 1787 * through [element], including defined in other files, correspond to each
1793 * other. But none of the results is guaranteed to be consistent with the state 1788 * other. But none of the results is guaranteed to be consistent with the state
1794 * of the files. 1789 * of the files.
1795 * 1790 *
1796 * Every result is independent, and is not guaranteed to be consistent with 1791 * Every result is independent, and is not guaranteed to be consistent with
1797 * any previously returned result, even inside of the same library. 1792 * any previously returned result, even inside of the same library.
1798 */ 1793 */
1799 class UnitElementResult { 1794 class UnitElementResult implements results.UnitElementResult {
1800 /** 1795 @override
1801 * The path of the file, absolute and normalized. 1796 final String filePath;
1802 */ 1797
1803 final String path; 1798 @override
1799 final Uri uri;
1804 1800
1805 /** 1801 /**
1806 * The signature of the [element] is based the APIs of the files of the 1802 * The signature of the [element] is based the APIs of the files of the
1807 * library (including the file itself) of the requested file and the 1803 * library (including the file itself) of the requested file and the
1808 * transitive closure of files imported and exported by the library. 1804 * transitive closure of files imported and exported by the library.
1809 */ 1805 */
1810 final String signature; 1806 final String signature;
1811 1807
1812 /** 1808 /**
1813 * The element of the file. 1809 * The element of the file.
1814 */ 1810 */
1815 final CompilationUnitElement element; 1811 final CompilationUnitElement element;
1816 1812
1817 UnitElementResult(this.path, this.signature, this.element); 1813 UnitElementResult(this.filePath, this.uri, this.signature, this.element);
1814
1815 /**
1816 * The path of the file, absolute and normalized.
1817 */
1818 //@deprecated
1819 String get path => filePath;
1820
1821 @override
1822 results.ResultState get state => results.ResultState.VALID;
1818 } 1823 }
1819 1824
1820 /** 1825 /**
1821 * Information about an exception and its context. 1826 * Information about an exception and its context.
1822 */ 1827 */
1823 class _ExceptionState { 1828 class _ExceptionState {
1824 final exception; 1829 final exception;
1825 final StackTrace stackTrace; 1830 final StackTrace stackTrace;
1826 1831
1827 /** 1832 /**
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 libraryDeclarations.add(new TopLevelDeclarationInSource( 2007 libraryDeclarations.add(new TopLevelDeclarationInSource(
2003 file.source, declaration, isExported)); 2008 file.source, declaration, isExported));
2004 } 2009 }
2005 } 2010 }
2006 } 2011 }
2007 2012
2008 // We're not done yet. 2013 // We're not done yet.
2009 return false; 2014 return false;
2010 } 2015 }
2011 } 2016 }
OLDNEW
« pkg/analyzer/lib/dart/analysis/results.dart ('K') | « pkg/analyzer/lib/dart/analysis/results.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698