Index: pkg/analyzer_experimental/lib/src/generated/engine.dart |
=================================================================== |
--- pkg/analyzer_experimental/lib/src/generated/engine.dart (revision 23549) |
+++ pkg/analyzer_experimental/lib/src/generated/engine.dart (working copy) |
@@ -17,33 +17,40 @@ |
import 'resolver.dart'; |
import 'html.dart' show XmlTagNode, XmlAttributeNode, RecursiveXmlVisitor, HtmlScanner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit; |
+ |
/** |
* The unique instance of the class {@code AnalysisEngine} serves as the entry point for the |
* functionality provided by the analysis engine. |
* @coverage dart.engine |
*/ |
class AnalysisEngine { |
+ |
/** |
* The suffix used for Dart source files. |
*/ |
static String SUFFIX_DART = "dart"; |
+ |
/** |
* The short suffix used for HTML files. |
*/ |
static String SUFFIX_HTM = "htm"; |
+ |
/** |
* The long suffix used for HTML files. |
*/ |
static String SUFFIX_HTML = "html"; |
+ |
/** |
* The unique instance of this class. |
*/ |
static AnalysisEngine _UniqueInstance = new AnalysisEngine(); |
+ |
/** |
* Return the unique instance of this class. |
* @return the unique instance of this class |
*/ |
static AnalysisEngine get instance => _UniqueInstance; |
+ |
/** |
* Return {@code true} if the given file name is assumed to contain Dart source code. |
* @param fileName the name of the file being tested |
@@ -55,6 +62,7 @@ |
} |
return javaStringEqualsIgnoreCase(FileNameUtilities.getExtension(fileName), SUFFIX_DART); |
} |
+ |
/** |
* Return {@code true} if the given file name is assumed to contain HTML. |
* @param fileName the name of the file being tested |
@@ -67,16 +75,13 @@ |
String extension = FileNameUtilities.getExtension(fileName); |
return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqualsIgnoreCase(extension, SUFFIX_HTM); |
} |
+ |
/** |
* The logger that should receive information about errors within the analysis engine. |
*/ |
Logger _logger = Logger.NULL; |
+ |
/** |
- * Prevent the creation of instances of this class. |
- */ |
- AnalysisEngine() : super() { |
- } |
- /** |
* Create a new context in which analysis can be performed. |
* @return the analysis context that was created |
*/ |
@@ -87,11 +92,13 @@ |
return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContextImpl()); |
} |
} |
+ |
/** |
* Return the logger that should receive information about errors within the analysis engine. |
* @return the logger that should receive information about errors within the analysis engine |
*/ |
Logger get logger => _logger; |
+ |
/** |
* Set the logger that should receive information about errors within the analysis engine to the |
* given logger. |
@@ -102,6 +109,7 @@ |
this._logger = logger2 == null ? Logger.NULL : logger2; |
} |
} |
+ |
/** |
* The interface {@code AnalysisContext} defines the behavior of objects that represent a context in |
* which a single analysis can be performed and incrementally maintained. The context includes such |
@@ -135,12 +143,14 @@ |
* proposed future state, such as the state after a refactoring. |
*/ |
abstract class AnalysisContext { |
+ |
/** |
* Apply the changes specified by the given change set to this context. Any analysis results that |
* have been invalidated by these changes will be removed. |
* @param changeSet a description of the changes that are to be applied |
*/ |
void applyChanges(ChangeSet changeSet); |
+ |
/** |
* Return the documentation comment for the given element as it appears in the original source |
* (complete with the beginning and ending delimiters), or {@code null} if the element does not |
@@ -152,6 +162,7 @@ |
* analysis could not be performed |
*/ |
String computeDocumentationComment(Element element); |
+ |
/** |
* Return an array containing all of the errors associated with the given source. If the errors |
* are not already known then the source will be analyzed in order to determine the errors |
@@ -163,6 +174,7 @@ |
* @see #getErrors(Source) |
*/ |
List<AnalysisError> computeErrors(Source source); |
+ |
/** |
* Return the element model corresponding to the HTML file defined by the given source. If the |
* element model does not yet exist it will be created. The process of creating an element model |
@@ -176,6 +188,7 @@ |
* @see #getHtmlElement(Source) |
*/ |
HtmlElement computeHtmlElement(Source source); |
+ |
/** |
* Return the kind of the given source, computing it's kind if it is not already known. Return{@link SourceKind#UNKNOWN} if the source is not contained in this context. |
* @param source the source whose kind is to be returned |
@@ -183,6 +196,7 @@ |
* @see #getKindOf(Source) |
*/ |
SourceKind computeKindOf(Source source); |
+ |
/** |
* Return the element model corresponding to the library defined by the given source. If the |
* element model does not yet exist it will be created. The process of creating an element model |
@@ -195,6 +209,7 @@ |
* @see #getLibraryElement(Source) |
*/ |
LibraryElement computeLibraryElement(Source source); |
+ |
/** |
* Return the line information for the given source, or {@code null} if the source is not of a |
* recognized kind (neither a Dart nor HTML file). If the line information was not previously |
@@ -207,6 +222,7 @@ |
* @see #getLineInfo(Source) |
*/ |
LineInfo computeLineInfo(Source source); |
+ |
/** |
* Create a new context in which analysis can be performed. Any sources in the specified container |
* will be removed from this context and added to the newly created context. |
@@ -215,7 +231,14 @@ |
* @return the analysis context that was created |
*/ |
AnalysisContext extractContext(SourceContainer container); |
+ |
/** |
+ * Return the set of analysis options controlling the behavior of this context. |
+ * @return the set of analysis options controlling the behavior of this context |
+ */ |
+ AnalysisOptions get analysisOptions; |
+ |
+ /** |
* Return the element referenced by the given location, or {@code null} if the element is not |
* immediately available or if there is no element with the given location. The latter condition |
* can occur, for example, if the location describes an element from a different context or if the |
@@ -225,6 +248,7 @@ |
* @return the element referenced by the given location |
*/ |
Element getElement(ElementLocation location); |
+ |
/** |
* Return an analysis error info containing the array of all of the errors and the line info |
* associated with the given source. The array of errors will be empty if the source is not known |
@@ -235,6 +259,7 @@ |
* @see #computeErrors(Source) |
*/ |
AnalysisErrorInfo getErrors(Source source); |
+ |
/** |
* Return the element model corresponding to the HTML file defined by the given source, or{@code null} if the source does not represent an HTML file, the element representing the file |
* has not yet been created, or the analysis of the HTML file failed for some reason. |
@@ -243,6 +268,7 @@ |
* @see #computeHtmlElement(Source) |
*/ |
HtmlElement getHtmlElement(Source source); |
+ |
/** |
* Return the sources for the HTML files that reference the given compilation unit. If the source |
* does not represent a Dart source or is not known to this context, the returned array will be |
@@ -251,12 +277,14 @@ |
* @return the sources for the HTML files that reference the given compilation unit |
*/ |
List<Source> getHtmlFilesReferencing(Source source); |
+ |
/** |
* Return an array containing all of the sources known to this context that represent HTML files. |
* The contents of the array can be incomplete. |
* @return the sources known to this context that represent HTML files |
*/ |
List<Source> get htmlSources; |
+ |
/** |
* Return the kind of the given source, or {@code null} if the kind is not known to this context. |
* @param source the source whose kind is to be returned |
@@ -264,6 +292,7 @@ |
* @see #computeKindOf(Source) |
*/ |
SourceKind getKindOf(Source source); |
+ |
/** |
* Return an array containing all of the sources known to this context that represent the defining |
* compilation unit of a library that can be run within a browser. The sources that are returned |
@@ -274,6 +303,7 @@ |
* library that can be run within a browser |
*/ |
List<Source> get launchableClientLibrarySources; |
+ |
/** |
* Return an array containing all of the sources known to this context that represent the defining |
* compilation unit of a library that can be run outside of a browser. The contents of the array |
@@ -282,6 +312,7 @@ |
* library that can be run outside of a browser |
*/ |
List<Source> get launchableServerLibrarySources; |
+ |
/** |
* Return the sources for the defining compilation units of any libraries of which the given |
* source is a part. The array will normally contain a single library because most Dart sources |
@@ -294,13 +325,24 @@ |
* @return the sources for the libraries containing the given source |
*/ |
List<Source> getLibrariesContaining(Source source); |
+ |
/** |
+ * Return the sources for the defining compilation units of any libraries that depend on the given |
+ * library. One library depends on another if it either imports or exports that library. |
+ * @param librarySource the source for the defining compilation unit of the library being depended |
+ * on |
+ * @return the sources for the libraries that depend on the given library |
+ */ |
+ List<Source> getLibrariesDependingOn(Source librarySource); |
+ |
+ /** |
* Return the element model corresponding to the library defined by the given source, or{@code null} if the element model does not currently exist or if the library cannot be analyzed |
* for some reason. |
* @param source the source defining the library whose element model is to be returned |
* @return the element model corresponding to the library defined by the given source |
*/ |
LibraryElement getLibraryElement(Source source); |
+ |
/** |
* Return an array containing all of the sources known to this context that represent the defining |
* compilation unit of a library. The contents of the array can be incomplete. |
@@ -308,6 +350,7 @@ |
* library |
*/ |
List<Source> get librarySources; |
+ |
/** |
* Return the line information for the given source, or {@code null} if the line information is |
* not known. The line information is used to map offsets from the beginning of the source to line |
@@ -317,6 +360,7 @@ |
* @see #computeLineInfo(Source) |
*/ |
LineInfo getLineInfo(Source source); |
+ |
/** |
* Return a fully resolved AST for a single compilation unit within the given library, or{@code null} if the resolved AST is not already computed. |
* @param unitSource the source of the compilation unit |
@@ -325,6 +369,7 @@ |
* @see #resolveCompilationUnit(Source,LibraryElement) |
*/ |
CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement library); |
+ |
/** |
* Return a fully resolved AST for a single compilation unit within the given library, or{@code null} if the resolved AST is not already computed. |
* @param unitSource the source of the compilation unit |
@@ -334,11 +379,13 @@ |
* @see #resolveCompilationUnit(Source,Source) |
*/ |
CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source librarySource); |
+ |
/** |
* Return the source factory used to create the sources that can be analyzed in this context. |
* @return the source factory used to create the sources that can be analyzed in this context |
*/ |
SourceFactory get sourceFactory; |
+ |
/** |
* Return {@code true} if the given source is known to be the defining compilation unit of a |
* library that can be run on a client (references 'dart:html', either directly or indirectly). |
@@ -350,6 +397,7 @@ |
* @return {@code true} if the given source is known to be a library that can be run on a client |
*/ |
bool isClientLibrary(Source librarySource); |
+ |
/** |
* Return {@code true} if the given source is known to be the defining compilation unit of a |
* library that can be run on the server (does not reference 'dart:html', either directly or |
@@ -363,6 +411,7 @@ |
* @return {@code true} if the given source is known to be a library that can be run on the server |
*/ |
bool isServerLibrary(Source librarySource); |
+ |
/** |
* Add the sources contained in the specified context to this context's collection of sources. |
* This method is called when an existing context's pubspec has been removed, and the contained |
@@ -370,6 +419,7 @@ |
* @param context the context being merged |
*/ |
void mergeContext(AnalysisContext context); |
+ |
/** |
* Parse a single source to produce an AST structure. The resulting AST structure may or may not |
* be resolved, and may have a slightly different structure depending upon whether it is resolved. |
@@ -378,6 +428,7 @@ |
* @throws AnalysisException if the analysis could not be performed |
*/ |
CompilationUnit parseCompilationUnit(Source source); |
+ |
/** |
* Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or |
* may not be resolved, and may have a slightly different structure depending upon whether it is |
@@ -387,6 +438,7 @@ |
* @throws AnalysisException if the analysis could not be performed |
*/ |
HtmlUnit parseHtmlUnit(Source source); |
+ |
/** |
* Perform the next unit of work required to keep the analysis results up-to-date and return |
* information about the consequent changes to the analysis results. If there were no results the |
@@ -395,6 +447,7 @@ |
* @return an array containing notices of changes to the analysis results |
*/ |
List<ChangeNotice> performAnalysisTask(); |
+ |
/** |
* Parse and resolve a single source within the given context to produce a fully resolved AST. |
* @param unitSource the source to be parsed and resolved |
@@ -405,6 +458,7 @@ |
* @see #getResolvedCompilationUnit(Source,LibraryElement) |
*/ |
CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement library); |
+ |
/** |
* Parse and resolve a single source within the given context to produce a fully resolved AST. |
* @param unitSource the source to be parsed and resolved |
@@ -416,6 +470,7 @@ |
* @see #getResolvedCompilationUnit(Source,Source) |
*/ |
CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySource); |
+ |
/** |
* Parse and resolve a single source within the given context to produce a fully resolved AST. |
* @param htmlSource the source to be parsed and resolved |
@@ -423,7 +478,15 @@ |
* @throws AnalysisException if the analysis could not be performed |
*/ |
HtmlUnit resolveHtmlUnit(Source htmlSource); |
+ |
/** |
+ * Set the set of analysis options controlling the behavior of this context to the given options. |
+ * Clients can safely assume that all necessary analysis results have been invalidated. |
+ * @param options the set of analysis options that will control the behavior of this context |
+ */ |
+ void set analysisOptions(AnalysisOptions options); |
+ |
+ /** |
* Set the contents of the given source to the given contents and mark the source as having |
* changed. This has the effect of overriding the default contents of the source. If the contents |
* are {@code null} the override is removed so that the default contents will be returned. |
@@ -431,6 +494,7 @@ |
* @param contents the new contents of the source |
*/ |
void setContents(Source source, String contents); |
+ |
/** |
* Set the source factory used to create the sources that can be analyzed in this context to the |
* given source factory. Clients can safely assume that all analysis results have been |
@@ -439,6 +503,7 @@ |
* context |
*/ |
void set sourceFactory(SourceFactory factory); |
+ |
/** |
* Given a collection of sources with content that has changed, return an {@link Iterable}identifying the sources that need to be resolved. |
* @param changedSources an array of sources (not {@code null}, contains no {@code null}s) |
@@ -446,16 +511,19 @@ |
*/ |
Iterable<Source> sourcesToResolve(List<Source> changedSources); |
} |
+ |
/** |
* The interface {@code AnalysisErrorInfo} contains the analysis errors and line information for the |
* errors. |
*/ |
abstract class AnalysisErrorInfo { |
+ |
/** |
* Return the errors that as a result of the analysis, or {@code null} if there were no errors. |
* @return the errors as a result of the analysis |
*/ |
List<AnalysisError> get errors; |
+ |
/** |
* Return the line information associated with the errors, or {@code null} if there were no |
* errors. |
@@ -463,12 +531,14 @@ |
*/ |
LineInfo get lineInfo; |
} |
+ |
/** |
* Instances of the class {@code AnalysisException} represent an exception that occurred during the |
* analysis of one or more sources. |
* @coverage dart.engine |
*/ |
class AnalysisException extends JavaException { |
+ |
/** |
* Initialize a newly created exception. |
*/ |
@@ -477,6 +547,7 @@ |
} |
_jtd_constructor_125_impl() { |
} |
+ |
/** |
* Initialize a newly created exception to have the given message. |
* @param message the message associated with the exception |
@@ -486,6 +557,7 @@ |
} |
_jtd_constructor_126_impl(String message) { |
} |
+ |
/** |
* Initialize a newly created exception to have the given message and cause. |
* @param message the message associated with the exception |
@@ -496,6 +568,7 @@ |
} |
_jtd_constructor_127_impl(String message, Exception cause) { |
} |
+ |
/** |
* Initialize a newly created exception to have the given cause. |
* @param cause the underlying exception that caused this exception |
@@ -506,52 +579,70 @@ |
_jtd_constructor_128_impl(Exception cause) { |
} |
} |
+ |
/** |
+ * The interface {@code AnalysisOptions} defines the behavior of objects that provide access to a |
+ * set of analysis options used to control the behavior of an analysis context. |
+ */ |
+abstract class AnalysisOptions { |
+ |
+ /** |
+ * Return {@code true} if analysis is to use strict mode. In strict mode, error reporting is based |
+ * exclusively on the static type information. |
+ * @return {@code true} if analysis is to use strict mode |
+ */ |
+ bool get strictMode; |
+} |
+ |
+/** |
* The interface {@code ChangeNotice} defines the behavior of objects that represent a change to the |
* analysis results associated with a given source. |
* @coverage dart.engine |
*/ |
abstract class ChangeNotice implements AnalysisErrorInfo { |
+ |
/** |
* Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the |
* AST was not changed. |
* @return the fully resolved AST that changed as a result of the analysis |
*/ |
CompilationUnit get compilationUnit; |
+ |
/** |
* Return the source for which the result is being reported. |
* @return the source for which the result is being reported |
*/ |
Source get source; |
} |
+ |
/** |
* Instances of the class {@code ChangeSet} indicate what sources have been added, changed, or |
* removed. |
* @coverage dart.engine |
*/ |
class ChangeSet { |
+ |
/** |
* A list containing the sources that have been added. |
*/ |
List<Source> _added2 = new List<Source>(); |
+ |
/** |
* A list containing the sources that have been changed. |
*/ |
List<Source> _changed2 = new List<Source>(); |
+ |
/** |
* A list containing the sources that have been removed. |
*/ |
List<Source> _removed2 = new List<Source>(); |
+ |
/** |
* A list containing the source containers specifying additional sources that have been removed. |
*/ |
List<SourceContainer> _removedContainers = new List<SourceContainer>(); |
+ |
/** |
- * Initialize a newly created change set to be empty. |
- */ |
- ChangeSet() : super() { |
- } |
- /** |
* Record that the specified source has been added and that it's content is the default contents |
* of the source. |
* @param source the source that was added |
@@ -559,6 +650,7 @@ |
void added(Source source) { |
_added2.add(source); |
} |
+ |
/** |
* Record that the specified source has been changed and that it's content is the default contents |
* of the source. |
@@ -567,31 +659,37 @@ |
void changed(Source source) { |
_changed2.add(source); |
} |
+ |
/** |
* Return a collection of the sources that have been added. |
* @return a collection of the sources that have been added |
*/ |
List<Source> get added3 => _added2; |
+ |
/** |
* Return a collection of sources that have been changed. |
* @return a collection of sources that have been changed |
*/ |
List<Source> get changed3 => _changed2; |
+ |
/** |
* Return a list containing the sources that were removed. |
* @return a list containing the sources that were removed |
*/ |
List<Source> get removed => _removed2; |
+ |
/** |
* Return a list containing the source containers that were removed. |
* @return a list containing the source containers that were removed |
*/ |
List<SourceContainer> get removedContainers => _removedContainers; |
+ |
/** |
* Return {@code true} if this change set does not contain any changes. |
* @return {@code true} if this change set does not contain any changes |
*/ |
bool isEmpty() => _added2.isEmpty && _changed2.isEmpty && _removed2.isEmpty && _removedContainers.isEmpty; |
+ |
/** |
* Record that the specified source has been removed. |
* @param source the source that was removed |
@@ -601,6 +699,7 @@ |
_removed2.add(source); |
} |
} |
+ |
/** |
* Record that the specified source container has been removed. |
* @param container the source container that was removed |
@@ -611,62 +710,81 @@ |
} |
} |
} |
+ |
/** |
* The interface {@code DartEntry} defines the behavior of objects that maintain the information |
* cached by an analysis context about an individual Dart file. |
* @coverage dart.engine |
*/ |
abstract class DartEntry implements SourceEntry { |
+ |
/** |
* The data descriptor representing the library element for the library. This data is only |
* available for Dart files that are the defining compilation unit of a library. |
*/ |
static DataDescriptor<LibraryElement> ELEMENT = new DataDescriptor<LibraryElement>("DartEntry.ELEMENT"); |
+ |
/** |
+ * The data descriptor representing the list of referenced libraries. This data is only available |
+ * for Dart files that are the defining compilation unit of a library. |
+ */ |
+ static DataDescriptor<List<Source>> REFERENCED_LIBRARIES = new DataDescriptor<List<Source>>("DartEntry.REFERENCED_LIBRARIES"); |
+ |
+ /** |
* The data descriptor representing the list of included parts. This data is only available for |
* Dart files that are the defining compilation unit of a library. |
*/ |
static DataDescriptor<List<Source>> INCLUDED_PARTS = new DataDescriptor<List<Source>>("DartEntry.INCLUDED_PARTS"); |
+ |
/** |
* The data descriptor representing the client flag. This data is only available for Dart files |
* that are the defining compilation unit of a library. |
*/ |
static DataDescriptor<bool> IS_CLIENT = new DataDescriptor<bool>("DartEntry.IS_CLIENT"); |
+ |
/** |
* The data descriptor representing the launchable flag. This data is only available for Dart |
* files that are the defining compilation unit of a library. |
*/ |
static DataDescriptor<bool> IS_LAUNCHABLE = new DataDescriptor<bool>("DartEntry.IS_LAUNCHABLE"); |
+ |
/** |
* The data descriptor representing the errors resulting from parsing the source. |
*/ |
static DataDescriptor<List<AnalysisError>> PARSE_ERRORS = new DataDescriptor<List<AnalysisError>>("DartEntry.PARSE_ERRORS"); |
+ |
/** |
* The data descriptor representing the parsed AST structure. |
*/ |
static DataDescriptor<CompilationUnit> PARSED_UNIT = new DataDescriptor<CompilationUnit>("DartEntry.PARSED_UNIT"); |
+ |
/** |
* The data descriptor representing the public namespace of the library. This data is only |
* available for Dart files that are the defining compilation unit of a library. |
*/ |
static DataDescriptor<Namespace> PUBLIC_NAMESPACE = new DataDescriptor<Namespace>("DartEntry.PUBLIC_NAMESPACE"); |
+ |
/** |
* The data descriptor representing the errors resulting from resolving the source. |
*/ |
static DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS = new DataDescriptor<List<AnalysisError>>("DartEntry.RESOLUTION_ERRORS"); |
+ |
/** |
* The data descriptor representing the resolved AST structure. |
*/ |
static DataDescriptor<CompilationUnit> RESOLVED_UNIT = new DataDescriptor<CompilationUnit>("DartEntry.RESOLVED_UNIT"); |
+ |
/** |
* The data descriptor representing the source kind. |
*/ |
static DataDescriptor<SourceKind> SOURCE_KIND = new DataDescriptor<SourceKind>("DartEntry.SOURCE_KIND"); |
+ |
/** |
* Return all of the errors associated with the compilation unit that are currently cached. |
* @return all of the errors associated with the compilation unit |
*/ |
List<AnalysisError> get allErrors; |
+ |
/** |
* Return a valid parsed compilation unit, either an unresolved AST structure or the result of |
* resolving the AST structure in the context of some library, or {@code null} if there is no |
@@ -674,12 +792,14 @@ |
* @return a valid parsed compilation unit |
*/ |
CompilationUnit get anyParsedCompilationUnit; |
+ |
/** |
* Return the result of resolving the compilation unit as part of any library, or {@code null} if |
* there is no cached resolved compilation unit. |
* @return any resolved compilation unit |
*/ |
CompilationUnit get anyResolvedCompilationUnit; |
+ |
/** |
* Return the state of the data represented by the given descriptor in the context of the given |
* library. |
@@ -689,6 +809,7 @@ |
* @return the value of the data represented by the given descriptor and library |
*/ |
CacheState getState2(DataDescriptor<Object> descriptor, Source librarySource); |
+ |
/** |
* Return the value of the data represented by the given descriptor in the context of the given |
* library, or {@code null} if the data represented by the descriptor is not in the cache. |
@@ -700,128 +821,132 @@ |
Object getValue2(DataDescriptor descriptor, Source librarySource); |
DartEntryImpl get writableCopy; |
} |
+ |
/** |
* Instances of the class {@code DartEntryImpl} implement a {@link DartEntry}. |
* @coverage dart.engine |
*/ |
class DartEntryImpl extends SourceEntryImpl implements DartEntry { |
+ |
/** |
* The state of the cached source kind. |
*/ |
CacheState _sourceKindState = CacheState.INVALID; |
+ |
/** |
* The kind of this source. |
*/ |
SourceKind _sourceKind = SourceKind.UNKNOWN; |
+ |
/** |
* The state of the cached parsed compilation unit. |
*/ |
CacheState _parsedUnitState = CacheState.INVALID; |
+ |
/** |
* The parsed compilation unit, or {@code null} if the parsed compilation unit is not currently |
* cached. |
*/ |
CompilationUnit _parsedUnit; |
+ |
/** |
* The state of the cached parse errors. |
*/ |
CacheState _parseErrorsState = CacheState.INVALID; |
+ |
/** |
* The errors produced while scanning and parsing the compilation unit, or {@code null} if the |
* errors are not currently cached. |
*/ |
List<AnalysisError> _parseErrors = AnalysisError.NO_ERRORS; |
+ |
/** |
* The state of the cached list of included parts. |
*/ |
CacheState _includedPartsState = CacheState.INVALID; |
+ |
/** |
- * The list of parts included in the library, or {@code null} if the list is not currently cached. |
- * The list will be empty if the Dart file is a part rather than a library. |
+ * The list of parts included in the library, or an empty array if the list is not currently |
+ * cached. The list will be empty if the Dart file is a part rather than a library. |
*/ |
List<Source> _includedParts = Source.EMPTY_ARRAY; |
+ |
/** |
- * The source for the defining compilation unit of the library that contains this unit, or{@code null} if this unit is contained in multiple libraries. (If this unit is the defining |
- * compilation unit for it's library, then this will be the source for this unit.) |
+ * The state of the cached list of referenced libraries. |
*/ |
- Source _librarySource; |
+ CacheState _referencedLibrariesState = CacheState.INVALID; |
+ |
/** |
+ * The list of libraries referenced (imported or exported) by the library, or an empty array if |
+ * the list is not currently cached. The list will be empty if the Dart file is a part rather than |
+ * a library. |
+ */ |
+ List<Source> _referencedLibraries = Source.EMPTY_ARRAY; |
+ |
+ /** |
* The information known as a result of resolving this compilation unit as part of the library |
- * that contains this unit, or {@code null} if this unit is contained in multiple libraries. |
+ * that contains this unit. This field will never be {@code null}. |
*/ |
DartEntryImpl_ResolutionState _resolutionState = new DartEntryImpl_ResolutionState(); |
+ |
/** |
- * A table mapping the sources of the libraries containing this compilation unit to the |
- * information known as a result of resolving this compilation unit as part of the library, or{@code null} if this unit is contained in a single library. |
- */ |
- Map<Source, DartEntryImpl_ResolutionState> _resolutionMap; |
- /** |
* The state of the cached library element. |
*/ |
CacheState _elementState = CacheState.INVALID; |
+ |
/** |
* The element representing the library, or {@code null} if the element is not currently cached. |
*/ |
LibraryElement _element; |
+ |
/** |
* The state of the cached public namespace. |
*/ |
CacheState _publicNamespaceState = CacheState.INVALID; |
+ |
/** |
* The public namespace of the library, or {@code null} if the namespace is not currently cached. |
*/ |
Namespace _publicNamespace; |
+ |
/** |
* The state of the cached client/ server flag. |
*/ |
CacheState _clientServerState = CacheState.INVALID; |
+ |
/** |
* The state of the cached launchable flag. |
*/ |
CacheState _launchableState = CacheState.INVALID; |
+ |
/** |
* An integer holding bit masks such as {@link #LAUNCHABLE} and {@link #CLIENT_CODE}. |
*/ |
int _bitmask = 0; |
+ |
/** |
* Mask indicating that this library is launchable: that the file has a main method. |
*/ |
static int _LAUNCHABLE = 1 << 1; |
+ |
/** |
* Mask indicating that the library is client code: that the library depends on the html library. |
* If the library is not "client code", then it is referenced as "server code". |
*/ |
static int _CLIENT_CODE = 1 << 2; |
- /** |
- * Initialize a newly created cache entry to be empty. |
- */ |
- DartEntryImpl() : super() { |
- } |
- /** |
- * Record the fact that we are about to parse the compilation unit by marking the results of |
- * parsing as being in progress. |
- */ |
- void aboutToParse() { |
- setState(SourceEntry.LINE_INFO, CacheState.IN_PROCESS); |
- _parsedUnitState = CacheState.IN_PROCESS; |
- _parseErrorsState = CacheState.IN_PROCESS; |
- } |
List<AnalysisError> get allErrors { |
List<AnalysisError> errors = new List<AnalysisError>(); |
for (AnalysisError error in _parseErrors) { |
errors.add(error); |
} |
- if (_resolutionMap == null) { |
- for (AnalysisError error in _resolutionState._resolutionErrors) { |
+ DartEntryImpl_ResolutionState state = _resolutionState; |
+ while (state != null) { |
+ for (AnalysisError error in state._resolutionErrors) { |
errors.add(error); |
} |
- } else { |
- for (DartEntryImpl_ResolutionState state in _resolutionMap.values) { |
- for (AnalysisError error in state._resolutionErrors) { |
- errors.add(error); |
- } |
- } |
+ state = state._nextState; |
} |
+ ; |
if (errors.length == 0) { |
return AnalysisError.NO_ERRORS; |
} |
@@ -831,23 +956,17 @@ |
if (identical(_parsedUnitState, CacheState.VALID)) { |
return _parsedUnit; |
} |
- if (_resolutionMap == null) { |
- return _resolutionState._resolvedUnit; |
- } else { |
- for (DartEntryImpl_ResolutionState state in _resolutionMap.values) { |
- if (identical(state._resolvedUnitState, CacheState.VALID)) { |
- return state._resolvedUnit; |
- } |
- } |
- } |
- return null; |
+ return anyResolvedCompilationUnit; |
} |
CompilationUnit get anyResolvedCompilationUnit { |
- for (DartEntryImpl_ResolutionState state in _resolutionMap.values) { |
+ DartEntryImpl_ResolutionState state = _resolutionState; |
+ while (state != null) { |
if (identical(state._resolvedUnitState, CacheState.VALID)) { |
return state._resolvedUnit; |
} |
+ state = state._nextState; |
} |
+ ; |
return null; |
} |
SourceKind get kind => _sourceKind; |
@@ -866,34 +985,29 @@ |
return _parsedUnitState; |
} else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { |
return _publicNamespaceState; |
+ } else if (identical(descriptor, DartEntry.REFERENCED_LIBRARIES)) { |
+ return _referencedLibrariesState; |
} else if (identical(descriptor, DartEntry.SOURCE_KIND)) { |
return _sourceKindState; |
} else { |
return super.getState(descriptor); |
} |
} |
- CacheState getState2(DataDescriptor<Object> descriptor, Source librarySource) { |
- if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
- if (_resolutionMap == null) { |
- return _resolutionState._resolutionErrorsState; |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource]; |
- if (state != null) { |
- return state._resolutionErrorsState; |
+ CacheState getState2(DataDescriptor<Object> descriptor, Source librarySource2) { |
+ DartEntryImpl_ResolutionState state = _resolutionState; |
+ while (state != null) { |
+ if (librarySource2 == state._librarySource) { |
+ if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
+ return _resolutionState._resolutionErrorsState; |
+ } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
+ return _resolutionState._resolvedUnitState; |
+ } else { |
+ throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
} |
- } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
- if (_resolutionMap == null) { |
- return _resolutionState._resolvedUnitState; |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource]; |
- if (state != null) { |
- return state._resolvedUnitState; |
- } |
- } |
- } else { |
- throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
+ state = state._nextState; |
} |
+ ; |
return CacheState.INVALID; |
} |
Object getValue(DataDescriptor descriptor) { |
@@ -911,67 +1025,129 @@ |
return _parsedUnit as Object; |
} else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { |
return _publicNamespace as Object; |
+ } else if (identical(descriptor, DartEntry.REFERENCED_LIBRARIES)) { |
+ return _referencedLibraries as Object; |
} else if (identical(descriptor, DartEntry.SOURCE_KIND)) { |
return _sourceKind as Object; |
} |
return super.getValue(descriptor); |
} |
Object getValue2(DataDescriptor descriptor, Source librarySource2) { |
- if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
- if (_resolutionMap == null) { |
- if (librarySource2 == this._librarySource) { |
- return _resolutionState._resolutionErrors as Object; |
+ DartEntryImpl_ResolutionState state = _resolutionState; |
+ while (state != null) { |
+ if (librarySource2 == state._librarySource) { |
+ if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
+ return state._resolutionErrors as Object; |
+ } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
+ return state._resolvedUnit as Object; |
} else { |
- return AnalysisError.NO_ERRORS as Object; |
+ throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource2]; |
- if (state != null) { |
- return state._resolutionErrors as Object; |
- } |
} |
+ state = state._nextState; |
+ } |
+ ; |
+ if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
+ return AnalysisError.NO_ERRORS as Object; |
} else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
- if (_resolutionMap == null) { |
- if (librarySource2 == this._librarySource) { |
- return _resolutionState._resolvedUnit as Object; |
- } else { |
- return null; |
- } |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource2]; |
- if (state != null) { |
- return state._resolvedUnit as Object; |
- } |
- } |
+ return null; |
} else { |
throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
- return null; |
} |
DartEntryImpl get writableCopy { |
DartEntryImpl copy = new DartEntryImpl(); |
copy.copyFrom(this); |
return copy; |
} |
+ |
/** |
+ * Invalidate all of the information associated with the compilation unit. |
+ */ |
+ void invalidateAllInformation() { |
+ setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
+ _sourceKind = SourceKind.UNKNOWN; |
+ _sourceKindState = CacheState.INVALID; |
+ _parseErrors = AnalysisError.NO_ERRORS; |
+ _parseErrorsState = CacheState.INVALID; |
+ _parsedUnit = null; |
+ _parsedUnitState = CacheState.INVALID; |
+ invalidateAllResolutionInformation(); |
+ } |
+ |
+ /** |
* Invalidate all of the resolution information associated with the compilation unit. |
*/ |
void invalidateAllResolutionInformation() { |
- if (_resolutionMap == null) { |
- _resolutionState.invalidateAllResolutionInformation(); |
- } else { |
- for (DartEntryImpl_ResolutionState state in _resolutionMap.values) { |
- state.invalidateAllResolutionInformation(); |
- } |
+ _element = null; |
+ _elementState = CacheState.INVALID; |
+ _includedParts = Source.EMPTY_ARRAY; |
+ _includedPartsState = CacheState.INVALID; |
+ _referencedLibraries = Source.EMPTY_ARRAY; |
+ _referencedLibrariesState = CacheState.INVALID; |
+ _bitmask = 0; |
+ _clientServerState = CacheState.INVALID; |
+ _launchableState = CacheState.INVALID; |
+ _publicNamespace = null; |
+ _publicNamespaceState = CacheState.INVALID; |
+ _resolutionState.invalidateAllResolutionInformation(); |
+ } |
+ |
+ /** |
+ * Record that an error occurred while attempting to scan or parse the entry represented by this |
+ * entry. This will set the state of all information, including any resolution-based information, |
+ * as being in error. |
+ */ |
+ void recordParseError() { |
+ setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
+ _sourceKind = SourceKind.UNKNOWN; |
+ _sourceKindState = CacheState.ERROR; |
+ _parseErrors = AnalysisError.NO_ERRORS; |
+ _parseErrorsState = CacheState.ERROR; |
+ _parsedUnit = null; |
+ _parsedUnitState = CacheState.ERROR; |
+ recordResolutionError(); |
+ } |
+ |
+ /** |
+ * Record that the parse-related information for the associated source is about to be computed by |
+ * the current thread. |
+ */ |
+ void recordParseInProcess() { |
+ if (getState(SourceEntry.LINE_INFO) != CacheState.VALID) { |
+ setState(SourceEntry.LINE_INFO, CacheState.IN_PROCESS); |
} |
- _elementState = CacheState.INVALID; |
+ if (_sourceKindState != CacheState.VALID) { |
+ _sourceKindState = CacheState.IN_PROCESS; |
+ } |
+ if (_parseErrorsState != CacheState.VALID) { |
+ _parseErrorsState = CacheState.IN_PROCESS; |
+ } |
+ if (_parsedUnitState != CacheState.VALID) { |
+ _parsedUnitState = CacheState.IN_PROCESS; |
+ } |
+ } |
+ |
+ /** |
+ * Record that an error occurred while attempting to scan or parse the entry represented by this |
+ * entry. This will set the state of all resolution-based information as being in error, but will |
+ * not change the state of any parse results. |
+ */ |
+ void recordResolutionError() { |
_element = null; |
- _publicNamespaceState = CacheState.INVALID; |
+ _elementState = CacheState.ERROR; |
+ _includedParts = Source.EMPTY_ARRAY; |
+ _includedPartsState = CacheState.ERROR; |
+ _referencedLibraries = Source.EMPTY_ARRAY; |
+ _referencedLibrariesState = CacheState.ERROR; |
+ _bitmask = 0; |
+ _clientServerState = CacheState.ERROR; |
+ _launchableState = CacheState.ERROR; |
_publicNamespace = null; |
- _launchableState = CacheState.INVALID; |
- _clientServerState = CacheState.INVALID; |
- _bitmask = 0; |
+ _publicNamespaceState = CacheState.ERROR; |
+ _resolutionState.recordResolutionError(); |
} |
+ |
/** |
* Remove any resolution information associated with this compilation unit being part of the given |
* library, presumably because it is no longer part of the library. |
@@ -979,21 +1155,28 @@ |
* contain this part but no longer does |
*/ |
void removeResolution(Source librarySource2) { |
- if (_resolutionMap == null) { |
- if (librarySource2 == this._librarySource) { |
- _resolutionState.invalidateAllResolutionInformation(); |
- this._librarySource = null; |
+ if (librarySource2 != null) { |
+ if (librarySource2 == _resolutionState._librarySource) { |
+ if (_resolutionState._nextState == null) { |
+ _resolutionState.invalidateAllResolutionInformation(); |
+ } else { |
+ _resolutionState = _resolutionState._nextState; |
+ } |
+ } else { |
+ DartEntryImpl_ResolutionState priorState = _resolutionState; |
+ DartEntryImpl_ResolutionState state = _resolutionState._nextState; |
+ while (state != null) { |
+ if (librarySource2 == state._librarySource) { |
+ priorState._nextState = state._nextState; |
+ break; |
+ } |
+ priorState = state; |
+ state = state._nextState; |
+ } |
} |
- } else { |
- _resolutionMap.remove(librarySource2); |
- if (_resolutionMap.length == 1) { |
- MapEntry<Source, DartEntryImpl_ResolutionState> entry = new JavaIterator(getMapEntrySet(_resolutionMap)).next(); |
- this._librarySource = entry.getKey(); |
- _resolutionState = entry.getValue(); |
- _resolutionMap = null; |
- } |
} |
} |
+ |
/** |
* Set the results of parsing the compilation unit at the given time to the given values. |
* @param modificationStamp the earliest time at which the source was last modified before the |
@@ -1035,6 +1218,9 @@ |
} else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { |
_publicNamespace = updatedValue(state, _publicNamespace, null); |
_publicNamespaceState = state; |
+ } else if (identical(descriptor, DartEntry.REFERENCED_LIBRARIES)) { |
+ _referencedLibraries = updatedValue(state, _referencedLibraries, Source.EMPTY_ARRAY); |
+ _referencedLibrariesState = state; |
} else if (identical(descriptor, DartEntry.SOURCE_KIND)) { |
_sourceKind = updatedValue(state, _sourceKind, SourceKind.UNKNOWN); |
_sourceKindState = state; |
@@ -1042,47 +1228,23 @@ |
super.setState(descriptor, state); |
} |
} |
+ |
/** |
* Set the state of the data represented by the given descriptor in the context of the given |
* library to the given state. |
* @param descriptor the descriptor representing the data whose state is to be set |
* @param librarySource the source of the defining compilation unit of the library that is the |
* context for the data |
- * @param state the new state of the data represented by the given descriptor |
+ * @param cacheState the new state of the data represented by the given descriptor |
*/ |
- void setState2(DataDescriptor<Object> descriptor, Source librarySource2, CacheState state) { |
- if (_resolutionMap == null && this._librarySource != librarySource2) { |
- _resolutionMap = new Map<Source, DartEntryImpl_ResolutionState>(); |
- _resolutionMap[this._librarySource] = _resolutionState; |
- this._librarySource = null; |
- _resolutionState = null; |
- } |
+ void setState2(DataDescriptor<Object> descriptor, Source librarySource, CacheState cacheState) { |
+ DartEntryImpl_ResolutionState state = getOrCreateResolutionState(librarySource); |
if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
- if (_resolutionMap == null) { |
- _resolutionState._resolutionErrors = updatedValue(state, _resolutionState._resolutionErrors, AnalysisError.NO_ERRORS); |
- _resolutionState._resolutionErrorsState = state; |
- } else { |
- DartEntryImpl_ResolutionState resolutionState = _resolutionMap[librarySource2]; |
- if (resolutionState == null) { |
- resolutionState = new DartEntryImpl_ResolutionState(); |
- _resolutionMap[librarySource2] = resolutionState; |
- } |
- resolutionState._resolutionErrors = updatedValue(state, resolutionState._resolutionErrors, AnalysisError.NO_ERRORS); |
- resolutionState._resolutionErrorsState = state; |
- } |
+ state._resolutionErrors = updatedValue(cacheState, state._resolutionErrors, AnalysisError.NO_ERRORS); |
+ state._resolutionErrorsState = cacheState; |
} else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
- if (_resolutionMap == null) { |
- _resolutionState._resolvedUnit = updatedValue(state, _resolutionState._resolvedUnit, null); |
- _resolutionState._resolvedUnitState = state; |
- } else { |
- DartEntryImpl_ResolutionState resolutionState = _resolutionMap[librarySource2]; |
- if (resolutionState == null) { |
- resolutionState = new DartEntryImpl_ResolutionState(); |
- _resolutionMap[librarySource2] = resolutionState; |
- } |
- resolutionState._resolvedUnit = updatedValue(state, resolutionState._resolvedUnit, null); |
- resolutionState._resolvedUnitState = state; |
- } |
+ state._resolvedUnit = updatedValue(cacheState, state._resolvedUnit, null); |
+ state._resolvedUnitState = cacheState; |
} else { |
throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
@@ -1117,6 +1279,9 @@ |
} else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { |
_publicNamespace = value as Namespace; |
_publicNamespaceState = CacheState.VALID; |
+ } else if (identical(descriptor, DartEntry.REFERENCED_LIBRARIES)) { |
+ _referencedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<Source>); |
+ _referencedLibrariesState = CacheState.VALID; |
} else if (identical(descriptor, DartEntry.SOURCE_KIND)) { |
_sourceKind = value as SourceKind; |
_sourceKindState = CacheState.VALID; |
@@ -1124,6 +1289,7 @@ |
super.setValue(descriptor, value); |
} |
} |
+ |
/** |
* Set the value of the data represented by the given descriptor in the context of the given |
* library to the given value, and set the state of that data to {@link CacheState#VALID}. |
@@ -1132,39 +1298,14 @@ |
* context for the data |
* @param value the new value of the data represented by the given descriptor and library |
*/ |
- void setValue2(DataDescriptor descriptor, Source librarySource2, Object value) { |
- if (_resolutionMap == null) { |
- if (this._librarySource == null) { |
- this._librarySource = librarySource2; |
- } else if (librarySource2 != this._librarySource) { |
- _resolutionMap = new Map<Source, DartEntryImpl_ResolutionState>(); |
- _resolutionMap[this._librarySource] = _resolutionState; |
- this._librarySource = null; |
- _resolutionState = null; |
- } |
- } |
+ void setValue2(DataDescriptor descriptor, Source librarySource, Object value) { |
+ DartEntryImpl_ResolutionState state = getOrCreateResolutionState(librarySource); |
if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { |
- if (_resolutionMap == null) { |
- _resolutionState._resolutionErrors = value == null ? AnalysisError.NO_ERRORS : (value as List<AnalysisError>); |
- _resolutionState._resolutionErrorsState = CacheState.VALID; |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource2]; |
- if (state != null) { |
- state._resolutionErrors = value == null ? AnalysisError.NO_ERRORS : (value as List<AnalysisError>); |
- state._resolutionErrorsState = CacheState.VALID; |
- } |
- } |
+ state._resolutionErrors = value == null ? AnalysisError.NO_ERRORS : (value as List<AnalysisError>); |
+ state._resolutionErrorsState = CacheState.VALID; |
} else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { |
- if (_resolutionMap == null) { |
- _resolutionState._resolvedUnit = value as CompilationUnit; |
- _resolutionState._resolvedUnitState = CacheState.VALID; |
- } else { |
- DartEntryImpl_ResolutionState state = _resolutionMap[librarySource2]; |
- if (state != null) { |
- state._resolvedUnit = value as CompilationUnit; |
- state._resolvedUnitState = CacheState.VALID; |
- } |
- } |
+ state._resolvedUnit = value as CompilationUnit; |
+ state._resolvedUnitState = CacheState.VALID; |
} |
} |
void copyFrom(SourceEntryImpl entry) { |
@@ -1178,19 +1319,9 @@ |
_parseErrors = other._parseErrors; |
_includedPartsState = other._includedPartsState; |
_includedParts = other._includedParts; |
- if (other._resolutionMap == null) { |
- _librarySource = other._librarySource; |
- DartEntryImpl_ResolutionState newState = new DartEntryImpl_ResolutionState(); |
- newState.copyFrom(_resolutionState); |
- _resolutionState = newState; |
- } else { |
- _resolutionMap = new Map<Source, DartEntryImpl_ResolutionState>(); |
- for (MapEntry<Source, DartEntryImpl_ResolutionState> mapEntry in getMapEntrySet(other._resolutionMap)) { |
- DartEntryImpl_ResolutionState newState = new DartEntryImpl_ResolutionState(); |
- newState.copyFrom(mapEntry.getValue()); |
- _resolutionMap[mapEntry.getKey()] = newState; |
- } |
- } |
+ _referencedLibrariesState = other._referencedLibrariesState; |
+ _referencedLibraries = other._referencedLibraries; |
+ _resolutionState.copyFrom(other._resolutionState); |
_elementState = other._elementState; |
_element = other._element; |
_publicNamespaceState = other._publicNamespaceState; |
@@ -1199,7 +1330,31 @@ |
_launchableState = other._launchableState; |
_bitmask = other._bitmask; |
} |
+ |
/** |
+ * Return a resolution state for the specified library, creating one as necessary. |
+ * @param librarySource the library source (not {@code null}) |
+ * @return the resolution state (not {@code null}) |
+ */ |
+ DartEntryImpl_ResolutionState getOrCreateResolutionState(Source librarySource2) { |
+ DartEntryImpl_ResolutionState state = _resolutionState; |
+ if (state._librarySource == null) { |
+ state._librarySource = librarySource2; |
+ return state; |
+ } |
+ while (state._librarySource != librarySource2) { |
+ if (state._nextState == null) { |
+ DartEntryImpl_ResolutionState newState = new DartEntryImpl_ResolutionState(); |
+ newState._librarySource = librarySource2; |
+ state._nextState = newState; |
+ return newState; |
+ } |
+ state = state._nextState; |
+ } |
+ return state; |
+ } |
+ |
+ /** |
* Given that one of the flags is being transitioned to the given state, return the value of the |
* flags that should be kept in the cache. |
* @param state the state to which the data is being transitioned |
@@ -1216,63 +1371,102 @@ |
return currentValue &= ~bitMask; |
} |
} |
+ |
/** |
* Instances of the class {@code ResolutionState} represent the information produced by resolving |
* a compilation unit as part of a specific library. |
*/ |
class DartEntryImpl_ResolutionState { |
+ |
/** |
+ * The next resolution state or {@code null} if none. |
+ */ |
+ DartEntryImpl_ResolutionState _nextState; |
+ |
+ /** |
+ * The source for the defining compilation unit of the library that contains this unit. If this |
+ * unit is the defining compilation unit for it's library, then this will be the source for this |
+ * unit. |
+ */ |
+ Source _librarySource; |
+ |
+ /** |
* The state of the cached resolved compilation unit. |
*/ |
CacheState _resolvedUnitState = CacheState.INVALID; |
+ |
/** |
* The resolved compilation unit, or {@code null} if the resolved compilation unit is not |
* currently cached. |
*/ |
CompilationUnit _resolvedUnit; |
+ |
/** |
* The state of the cached resolution errors. |
*/ |
CacheState _resolutionErrorsState = CacheState.INVALID; |
+ |
/** |
* The errors produced while resolving the compilation unit, or {@code null} if the errors are |
* not currently cached. |
*/ |
List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS; |
+ |
/** |
- * Initialize a newly created resolution state. |
- */ |
- DartEntryImpl_ResolutionState() : super() { |
- } |
- /** |
- * Set this state to be exactly like the given state. |
+ * Set this state to be exactly like the given state, recursively copying the next state as |
+ * necessary. |
* @param other the state to be copied |
*/ |
void copyFrom(DartEntryImpl_ResolutionState other) { |
+ _librarySource = other._librarySource; |
_resolvedUnitState = other._resolvedUnitState; |
_resolvedUnit = other._resolvedUnit; |
_resolutionErrorsState = other._resolutionErrorsState; |
_resolutionErrors = other._resolutionErrors; |
+ if (other._nextState != null) { |
+ _nextState = new DartEntryImpl_ResolutionState(); |
+ _nextState.copyFrom(other._nextState); |
+ } |
} |
+ |
/** |
* Invalidate all of the resolution information associated with the compilation unit. |
*/ |
void invalidateAllResolutionInformation() { |
+ _nextState = null; |
+ _librarySource = null; |
_resolvedUnitState = CacheState.INVALID; |
_resolvedUnit = null; |
_resolutionErrorsState = CacheState.INVALID; |
_resolutionErrors = AnalysisError.NO_ERRORS; |
} |
+ |
+ /** |
+ * Record that an error occurred while attempting to scan or parse the entry represented by this |
+ * entry. This will set the state of all resolution-based information as being in error, but |
+ * will not change the state of any parse results. |
+ */ |
+ void recordResolutionError() { |
+ _nextState = null; |
+ _librarySource = null; |
+ _resolvedUnitState = CacheState.ERROR; |
+ _resolvedUnit = null; |
+ _resolutionErrorsState = CacheState.ERROR; |
+ _resolutionErrors = AnalysisError.NO_ERRORS; |
+ } |
} |
+ |
/** |
* Instances of the class {@code DataDescriptor} are immutable constants representing data that can |
* be stored in the cache. |
*/ |
class DataDescriptor<E> { |
+ |
/** |
* The name of the descriptor, used for debugging purposes. |
*/ |
String _name; |
+ |
/** |
* Initialize a newly created descriptor to have the given name. |
* @param name the name of the descriptor |
@@ -1282,85 +1476,113 @@ |
} |
String toString() => _name; |
} |
+ |
/** |
* The interface {@code HtmlEntry} defines the behavior of objects that maintain the information |
* cached by an analysis context about an individual HTML file. |
* @coverage dart.engine |
*/ |
abstract class HtmlEntry implements SourceEntry { |
+ |
/** |
* The data descriptor representing the HTML element. |
*/ |
static DataDescriptor<HtmlElement> ELEMENT = new DataDescriptor<HtmlElement>("HtmlEntry.ELEMENT"); |
+ |
/** |
* The data descriptor representing the parsed AST structure. |
*/ |
static DataDescriptor<HtmlUnit> PARSED_UNIT = new DataDescriptor<HtmlUnit>("HtmlEntry.PARSED_UNIT"); |
+ |
/** |
* The data descriptor representing the list of referenced libraries. |
*/ |
static DataDescriptor<List<Source>> REFERENCED_LIBRARIES = new DataDescriptor<List<Source>>("HtmlEntry.REFERENCED_LIBRARIES"); |
+ |
/** |
* The data descriptor representing the errors resulting from resolving the source. |
*/ |
static DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS = new DataDescriptor<List<AnalysisError>>("HtmlEntry.RESOLUTION_ERRORS"); |
+ |
/** |
* The data descriptor representing the resolved AST structure. |
*/ |
static DataDescriptor<HtmlUnit> RESOLVED_UNIT = new DataDescriptor<HtmlUnit>("HtmlEntry.RESOLVED_UNIT"); |
+ |
+ /** |
+ * Return all of the errors associated with the compilation unit that are currently cached. |
+ * @return all of the errors associated with the compilation unit |
+ */ |
+ List<AnalysisError> get allErrors; |
HtmlEntryImpl get writableCopy; |
} |
+ |
/** |
* Instances of the class {@code HtmlEntryImpl} implement an {@link HtmlEntry}. |
* @coverage dart.engine |
*/ |
class HtmlEntryImpl extends SourceEntryImpl implements HtmlEntry { |
+ |
/** |
* The state of the cached parsed (but not resolved) HTML unit. |
*/ |
CacheState _parsedUnitState = CacheState.INVALID; |
+ |
/** |
* The parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached. |
*/ |
HtmlUnit _parsedUnit; |
+ |
/** |
* The state of the cached resolution errors. |
*/ |
CacheState _resolutionErrorsState = CacheState.INVALID; |
+ |
/** |
* The errors produced while resolving the compilation unit, or {@code null} if the errors are not |
* currently cached. |
*/ |
List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS; |
+ |
/** |
* The state of the cached parsed and resolved HTML unit. |
*/ |
CacheState _resolvedUnitState = CacheState.INVALID; |
+ |
/** |
* The resolved HTML unit, or {@code null} if the resolved HTML unit is not currently cached. |
*/ |
HtmlUnit _resolvedUnit; |
+ |
/** |
* The state of the cached list of referenced libraries. |
*/ |
CacheState _referencedLibrariesState = CacheState.INVALID; |
+ |
/** |
* The list of libraries referenced in the HTML, or {@code null} if the list is not currently |
* cached. Note that this list does not include libraries defined directly within the HTML file. |
*/ |
List<Source> _referencedLibraries = Source.EMPTY_ARRAY; |
+ |
/** |
* The state of the cached HTML element. |
*/ |
CacheState _elementState = CacheState.INVALID; |
+ |
/** |
* The element representing the HTML file, or {@code null} if the element is not currently cached. |
*/ |
HtmlElement _element; |
- /** |
- * Initialize a newly created cache entry to be empty. |
- */ |
- HtmlEntryImpl() : super() { |
+ List<AnalysisError> get allErrors { |
+ List<AnalysisError> errors = new List<AnalysisError>(); |
+ for (AnalysisError error in _resolutionErrors) { |
+ errors.add(error); |
+ } |
+ if (errors.length == 0) { |
+ return AnalysisError.NO_ERRORS; |
+ } |
+ return new List.from(errors); |
} |
SourceKind get kind => SourceKind.HTML; |
CacheState getState(DataDescriptor<Object> descriptor) { |
@@ -1451,6 +1673,7 @@ |
_element = other._element; |
} |
} |
+ |
/** |
* The interface {@code SourceEntry} defines the behavior of objects that maintain the information |
* cached by an analysis context about an individual source, no matter what kind of source it is. |
@@ -1460,27 +1683,32 @@ |
* @coverage dart.engine |
*/ |
abstract class SourceEntry { |
+ |
/** |
* The data descriptor representing the line information. |
*/ |
static DataDescriptor<LineInfo> LINE_INFO = new DataDescriptor<LineInfo>("SourceEntry.LINE_INFO"); |
+ |
/** |
* Return the kind of the source, or {@code null} if the kind is not currently cached. |
* @return the kind of the source |
*/ |
SourceKind get kind; |
+ |
/** |
* Return the most recent time at which the state of the source matched the state represented by |
* this entry. |
* @return the modification time of this entry |
*/ |
int get modificationTime; |
+ |
/** |
* Return the state of the data represented by the given descriptor. |
* @param descriptor the descriptor representing the data whose state is to be returned |
* @return the state of the data represented by the given descriptor |
*/ |
CacheState getState(DataDescriptor<Object> descriptor); |
+ |
/** |
* Return the value of the data represented by the given descriptor, or {@code null} if the data |
* represented by the descriptor is not in the cache. |
@@ -1488,6 +1716,7 @@ |
* @return the value of the data represented by the given descriptor |
*/ |
Object getValue(DataDescriptor descriptor); |
+ |
/** |
* Return a new entry that is initialized to the same state as this entry but that can be |
* modified. |
@@ -1495,30 +1724,29 @@ |
*/ |
SourceEntryImpl get writableCopy; |
} |
+ |
/** |
* Instances of the abstract class {@code SourceEntryImpl} implement the behavior common to all{@link SourceEntry source entries}. |
* @coverage dart.engine |
*/ |
abstract class SourceEntryImpl implements SourceEntry { |
+ |
/** |
* The most recent time at which the state of the source matched the state represented by this |
* entry. |
*/ |
int _modificationTime = 0; |
+ |
/** |
* The state of the cached line information. |
*/ |
CacheState _lineInfoState = CacheState.INVALID; |
+ |
/** |
* The line information computed for the source, or {@code null} if the line information is not |
* currently cached. |
*/ |
LineInfo _lineInfo; |
- /** |
- * Initialize a newly created cache entry to be empty. |
- */ |
- SourceEntryImpl() : super() { |
- } |
int get modificationTime => _modificationTime; |
CacheState getState(DataDescriptor<Object> descriptor) { |
if (identical(descriptor, SourceEntry.LINE_INFO)) { |
@@ -1534,6 +1762,7 @@ |
throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
} |
+ |
/** |
* Set the most recent time at which the state of the source matched the state represented by this |
* entry to the given time. |
@@ -1542,6 +1771,7 @@ |
void set modificationTime(int time) { |
_modificationTime = time; |
} |
+ |
/** |
* Set the state of the data represented by the given descriptor to the given state. |
* @param descriptor the descriptor representing the data whose state is to be set |
@@ -1555,6 +1785,7 @@ |
throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
} |
+ |
/** |
* Set the value of the data represented by the given descriptor to the given value. |
* @param descriptor the descriptor representing the data whose value is to be set |
@@ -1568,6 +1799,7 @@ |
throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); |
} |
} |
+ |
/** |
* Copy the information from the given cache entry. |
* @param entry the cache entry from which information will be copied |
@@ -1577,6 +1809,7 @@ |
_lineInfoState = entry._lineInfoState; |
_lineInfo = entry._lineInfo; |
} |
+ |
/** |
* Given that some data is being transitioned to the given state, return the value that should be |
* kept in the cache. |
@@ -1594,57 +1827,67 @@ |
return defaultValue; |
} |
} |
+ |
/** |
* Instances of the class {@code AnalysisContextImpl} implement an {@link AnalysisContext analysis |
* context}. |
* @coverage dart.engine |
*/ |
class AnalysisContextImpl implements InternalAnalysisContext { |
+ |
/** |
+ * The set of analysis options controlling the behavior of this context. |
+ */ |
+ AnalysisOptions _options = new AnalysisOptionsImpl(); |
+ |
+ /** |
* The source factory used to create the sources that can be analyzed in this context. |
*/ |
SourceFactory _sourceFactory; |
+ |
/** |
* A table mapping the sources known to the context to the information known about the source. |
*/ |
Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>(); |
+ |
/** |
* A table mapping sources to the change notices that are waiting to be returned related to that |
* source. |
*/ |
Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeImpl>(); |
+ |
/** |
* A list containing the most recently accessed sources with the most recently used at the end of |
* the list. When more sources are added than the maximum allowed then the least recently used |
* source will be removed and will have it's cached AST structure flushed. |
*/ |
List<Source> _recentlyUsed = new List<Source>(); |
+ |
/** |
* The object used to synchronize access to all of the caches. |
*/ |
Object _cacheLock = new Object(); |
+ |
/** |
* The maximum number of sources for which data should be kept in the cache. |
*/ |
static int _MAX_CACHE_SIZE = 64; |
+ |
/** |
* The name of the 'src' attribute in a HTML tag. |
*/ |
static String _ATTRIBUTE_SRC = "src"; |
+ |
/** |
* The name of the 'script' tag in an HTML file. |
*/ |
static String _TAG_SCRIPT = "script"; |
+ |
/** |
* The number of times that the flushing of information from the cache has been disabled without |
* being re-enabled. |
*/ |
int _cacheRemovalCount = 0; |
- /** |
- * Initialize a newly created analysis context. |
- */ |
- AnalysisContextImpl() : super() { |
- } |
void addSourceInfo(Source source, SourceEntry info) { |
_sourceMap[source] = info; |
} |
@@ -1672,7 +1915,9 @@ |
if (addedDartSource) { |
for (MapEntry<Source, SourceEntry> mapEntry in getMapEntrySet(_sourceMap)) { |
if (!mapEntry.getKey().isInSystemLibrary() && mapEntry.getValue() is DartEntry) { |
- ((mapEntry.getValue() as DartEntryImpl)).invalidateAllResolutionInformation(); |
+ DartEntryImpl dartCopy = ((mapEntry.getValue() as DartEntry)).writableCopy; |
+ dartCopy.invalidateAllResolutionInformation(); |
+ mapEntry.setValue(dartCopy); |
} |
} |
} |
@@ -1688,7 +1933,7 @@ |
} |
List<CharSequence> contentHolder = new List<CharSequence>(1); |
try { |
- source2.getContents(new Source_ContentReceiver_5(contentHolder)); |
+ source2.getContents(new Source_ContentReceiver_6(contentHolder)); |
} catch (exception) { |
throw new AnalysisException.con2("Could not get contents of ${source2.fullName}", exception); |
} |
@@ -1722,6 +1967,7 @@ |
CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERRORS); |
if (parseErrorsState != CacheState.VALID && parseErrorsState != CacheState.ERROR) { |
parseCompilationUnit(source); |
+ dartEntry = getSourceEntry(source) as DartEntry; |
} |
List<Source> libraries = getLibrariesContaining(source); |
for (Source librarySource in libraries) { |
@@ -1735,6 +1981,7 @@ |
CacheState resolutionErrorsState = htmlEntry.getState(HtmlEntry.RESOLUTION_ERRORS); |
if (resolutionErrorsState != CacheState.VALID && resolutionErrorsState != CacheState.ERROR) { |
computeHtmlElement(source); |
+ htmlEntry = getSourceEntry(source) as HtmlEntry; |
} |
return htmlEntry.getValue(HtmlEntry.RESOLUTION_ERRORS); |
} |
@@ -1759,15 +2006,15 @@ |
unit = parseHtmlUnit(source); |
} |
} |
- RecordingErrorListener listener = new RecordingErrorListener(); |
- HtmlUnitBuilder builder = new HtmlUnitBuilder(this, listener); |
+ HtmlUnitBuilder builder = new HtmlUnitBuilder(this); |
element = builder.buildHtmlElement2(source, unit); |
- List<AnalysisError> resolutionErrors = listener.getErrors2(source); |
- HtmlEntryImpl htmlCopy = (htmlEntry as HtmlEntryImpl); |
+ List<AnalysisError> resolutionErrors = builder.errorListener.getErrors2(source); |
+ HtmlEntryImpl htmlCopy = getHtmlEntry(source).writableCopy; |
htmlCopy.setValue(HtmlEntry.RESOLVED_UNIT, unit); |
htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, resolutionErrors); |
htmlCopy.setValue(HtmlEntry.ELEMENT, element); |
- getNotice(source).setErrors(resolutionErrors, htmlCopy.getValue(SourceEntry.LINE_INFO)); |
+ _sourceMap[source] = htmlCopy; |
+ getNotice(source).setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LINE_INFO)); |
} |
return element; |
} |
@@ -1782,6 +2029,7 @@ |
CacheState sourceKindState = dartEntry.getState(DartEntry.SOURCE_KIND); |
if (sourceKindState != CacheState.VALID && sourceKindState != CacheState.ERROR) { |
internalComputeKindOf(source); |
+ sourceEntry = getSourceEntry(source); |
} |
} |
return sourceEntry.kind; |
@@ -1798,16 +2046,14 @@ |
} |
LibraryElement element = dartEntry.getValue(DartEntry.ELEMENT); |
if (element == null) { |
- if (computeKindOf(source) != SourceKind.LIBRARY) { |
- throw new AnalysisException.con1("Cannot compute library element for non-library: ${source.fullName}"); |
- } |
- LibraryResolver resolver = new LibraryResolver.con1(this); |
+ LibraryResolver resolver = new LibraryResolver(this); |
try { |
element = resolver.resolveLibrary(source, true); |
- if (element != null) { |
- ((dartEntry as DartEntryImpl)).setValue(DartEntry.ELEMENT, element); |
- } |
+ recordResolutionResults(resolver); |
} on AnalysisException catch (exception) { |
+ DartEntryImpl dartCopy = getDartEntry(source).writableCopy; |
+ dartCopy.setState(DartEntry.ELEMENT, CacheState.ERROR); |
+ _sourceMap[source] = dartCopy; |
AnalysisEngine.instance.logger.logError2("Could not resolve the library ${source.fullName}", exception); |
} |
} |
@@ -1824,10 +2070,10 @@ |
if (lineInfo == null) { |
if (sourceEntry is HtmlEntry) { |
parseHtmlUnit(source); |
- lineInfo = sourceEntry.getValue(SourceEntry.LINE_INFO); |
+ lineInfo = getSourceEntry(source).getValue(SourceEntry.LINE_INFO); |
} else if (sourceEntry is DartEntry) { |
parseCompilationUnit(source); |
- lineInfo = sourceEntry.getValue(SourceEntry.LINE_INFO); |
+ lineInfo = getSourceEntry(source).getValue(SourceEntry.LINE_INFO); |
} |
} |
return lineInfo; |
@@ -1843,12 +2089,14 @@ |
if (unit != null) { |
return unit.accept(new ASTCloner()) as CompilationUnit; |
} |
- unit = internalParseCompilationUnit(((dartEntry as DartEntryImpl)), source); |
- ((dartEntry as DartEntryImpl)).setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ unit = internalParseCompilationUnit(dartCopy, source); |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ _sourceMap[source] = dartCopy; |
return unit; |
} |
} |
- AnalysisContext extractContext(SourceContainer container) => extractContextInto(container, (AnalysisEngine.instance.createAnalysisContext() as AnalysisContextImpl)); |
+ AnalysisContext extractContext(SourceContainer container) => extractContextInto(container, (AnalysisEngine.instance.createAnalysisContext() as InternalAnalysisContext)); |
InternalAnalysisContext extractContextInto(SourceContainer container, InternalAnalysisContext newContext) { |
List<Source> sourcesToRemove = new List<Source>(); |
{ |
@@ -1862,6 +2110,7 @@ |
} |
return newContext; |
} |
+ AnalysisOptions get analysisOptions => _options; |
Element getElement(ElementLocation location) { |
List<String> components2 = ((location as ElementLocationImpl)).components; |
ElementImpl element; |
@@ -1882,26 +2131,22 @@ |
return element; |
} |
AnalysisErrorInfo getErrors(Source source) { |
- { |
- SourceEntry sourceEntry = getSourceEntry(source); |
- if (sourceEntry is DartEntry) { |
- DartEntry dartEntry = sourceEntry as DartEntry; |
- return new AnalysisErrorInfoImpl(dartEntry.allErrors, dartEntry.getValue(SourceEntry.LINE_INFO)); |
- } else if (sourceEntry is HtmlEntry) { |
- HtmlEntry htmlEntry = sourceEntry as HtmlEntry; |
- return new AnalysisErrorInfoImpl(htmlEntry.getValue(HtmlEntry.RESOLUTION_ERRORS), htmlEntry.getValue(SourceEntry.LINE_INFO)); |
- } |
- return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, sourceEntry.getValue(SourceEntry.LINE_INFO)); |
+ SourceEntry sourceEntry = getReadableSourceEntry(source); |
+ if (sourceEntry is DartEntry) { |
+ DartEntry dartEntry = sourceEntry as DartEntry; |
+ return new AnalysisErrorInfoImpl(dartEntry.allErrors, dartEntry.getValue(SourceEntry.LINE_INFO)); |
+ } else if (sourceEntry is HtmlEntry) { |
+ HtmlEntry htmlEntry = sourceEntry as HtmlEntry; |
+ return new AnalysisErrorInfoImpl(htmlEntry.allErrors, htmlEntry.getValue(SourceEntry.LINE_INFO)); |
} |
+ return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null); |
} |
HtmlElement getHtmlElement(Source source) { |
- { |
- SourceEntry sourceEntry = getSourceEntry(source); |
- if (sourceEntry is HtmlEntry) { |
- return ((sourceEntry as HtmlEntry)).getValue(HtmlEntry.ELEMENT); |
- } |
- return null; |
+ SourceEntry sourceEntry = getReadableSourceEntry(source); |
+ if (sourceEntry is HtmlEntry) { |
+ return ((sourceEntry as HtmlEntry)).getValue(HtmlEntry.ELEMENT); |
} |
+ return null; |
} |
List<Source> getHtmlFilesReferencing(Source source) { |
{ |
@@ -1929,13 +2174,14 @@ |
} |
List<Source> get htmlSources => getSources(SourceKind.HTML); |
SourceKind getKindOf(Source source) { |
- { |
- SourceEntry sourceEntry = getSourceEntry(source); |
- if (sourceEntry == null) { |
- return SourceKind.UNKNOWN; |
+ SourceEntry sourceEntry = getReadableSourceEntry(source); |
+ if (sourceEntry == null) { |
+ if (AnalysisEngine.isHtmlFileName(source.shortName)) { |
+ return SourceKind.HTML; |
} |
- return sourceEntry.kind; |
+ return SourceKind.UNKNOWN; |
} |
+ return sourceEntry.kind; |
} |
List<Source> get launchableClientLibrarySources { |
List<Source> sources = new List<Source>(); |
@@ -1979,24 +2225,36 @@ |
return new List.from(librarySources); |
} |
} |
- LibraryElement getLibraryElement(Source source) { |
+ List<Source> getLibrariesDependingOn(Source librarySource) { |
{ |
- SourceEntry sourceEntry = getSourceEntry(source); |
- if (sourceEntry is DartEntry) { |
- return ((sourceEntry as DartEntry)).getValue(DartEntry.ELEMENT); |
+ List<Source> dependentLibraries = new List<Source>(); |
+ for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { |
+ if (identical(entry.getValue().kind, SourceKind.LIBRARY)) { |
+ if (contains(((entry.getValue() as DartEntry)).getValue(DartEntry.REFERENCED_LIBRARIES), librarySource)) { |
+ dependentLibraries.add(entry.getKey()); |
+ } |
+ } |
} |
- return null; |
+ if (dependentLibraries.isEmpty) { |
+ return Source.EMPTY_ARRAY; |
+ } |
+ return new List.from(dependentLibraries); |
} |
} |
+ LibraryElement getLibraryElement(Source source) { |
+ SourceEntry sourceEntry = getReadableSourceEntry(source); |
+ if (sourceEntry is DartEntry) { |
+ return ((sourceEntry as DartEntry)).getValue(DartEntry.ELEMENT); |
+ } |
+ return null; |
+ } |
List<Source> get librarySources => getSources(SourceKind.LIBRARY); |
LineInfo getLineInfo(Source source) { |
- { |
- SourceEntry sourceEntry = getSourceEntry(source); |
- if (sourceEntry != null) { |
- return sourceEntry.getValue(SourceEntry.LINE_INFO); |
- } |
- return null; |
+ SourceEntry sourceEntry = getReadableSourceEntry(source); |
+ if (sourceEntry != null) { |
+ return sourceEntry.getValue(SourceEntry.LINE_INFO); |
} |
+ return null; |
} |
Namespace getPublicNamespace(LibraryElement library) { |
Source source2 = library.definingCompilationUnit.source; |
@@ -2009,7 +2267,9 @@ |
if (namespace == null) { |
NamespaceBuilder builder = new NamespaceBuilder(); |
namespace = builder.createPublicNamespace(library); |
- ((dartEntry as DartEntryImpl)).setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
+ _sourceMap[source2] = dartCopy; |
} |
return namespace; |
} |
@@ -2028,7 +2288,9 @@ |
} |
NamespaceBuilder builder = new NamespaceBuilder(); |
namespace = builder.createPublicNamespace(library); |
- ((dartEntry as DartEntryImpl)).setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
+ _sourceMap[source] = dartCopy; |
} |
return namespace; |
} |
@@ -2040,38 +2302,25 @@ |
return getResolvedCompilationUnit2(unitSource, library.source); |
} |
CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source librarySource) { |
- { |
- accessed(unitSource); |
- DartEntry dartEntry = getDartEntry(unitSource); |
- if (dartEntry == null) { |
- return null; |
- } |
- return dartEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource); |
+ SourceEntry sourceEntry = getReadableSourceEntry(unitSource); |
+ if (sourceEntry is DartEntry) { |
+ return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, librarySource); |
} |
+ return null; |
} |
SourceFactory get sourceFactory => _sourceFactory; |
bool isClientLibrary(Source librarySource) { |
- SourceEntry sourceEntry = getSourceEntry(librarySource); |
+ SourceEntry sourceEntry = getReadableSourceEntry(librarySource); |
if (sourceEntry is DartEntry) { |
DartEntry dartEntry = sourceEntry as DartEntry; |
- CacheState isClientState = dartEntry.getState(DartEntry.IS_CLIENT); |
- CacheState isLaunchableState = dartEntry.getState(DartEntry.IS_LAUNCHABLE); |
- if (identical(isClientState, CacheState.INVALID) || identical(isClientState, CacheState.ERROR) || identical(isLaunchableState, CacheState.INVALID) || identical(isLaunchableState, CacheState.ERROR)) { |
- return false; |
- } |
return dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartEntry.IS_LAUNCHABLE); |
} |
return false; |
} |
bool isServerLibrary(Source librarySource) { |
- SourceEntry sourceEntry = getSourceEntry(librarySource); |
+ SourceEntry sourceEntry = getReadableSourceEntry(librarySource); |
if (sourceEntry is DartEntry) { |
DartEntry dartEntry = sourceEntry as DartEntry; |
- CacheState isClientState = dartEntry.getState(DartEntry.IS_CLIENT); |
- CacheState isLaunchableState = dartEntry.getState(DartEntry.IS_LAUNCHABLE); |
- if (identical(isClientState, CacheState.INVALID) || identical(isClientState, CacheState.ERROR) || identical(isLaunchableState, CacheState.INVALID) || identical(isLaunchableState, CacheState.ERROR)) { |
- return false; |
- } |
return !dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartEntry.IS_LAUNCHABLE); |
} |
return false; |
@@ -2097,7 +2346,9 @@ |
} |
CompilationUnit unit = dartEntry.anyParsedCompilationUnit; |
if (unit == null) { |
- unit = internalParseCompilationUnit((dartEntry as DartEntryImpl), source); |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ unit = internalParseCompilationUnit(dartCopy, source); |
+ _sourceMap[source] = dartCopy; |
} |
return unit; |
} |
@@ -2115,9 +2366,11 @@ |
if (unit == null) { |
HtmlParseResult result = new HtmlParser(source).parse(scanHtml(source)); |
unit = result.htmlUnit; |
- ((htmlEntry as HtmlEntryImpl)).setValue(SourceEntry.LINE_INFO, new LineInfo(result.lineStarts)); |
- ((htmlEntry as HtmlEntryImpl)).setValue(HtmlEntry.PARSED_UNIT, unit); |
- ((htmlEntry as HtmlEntryImpl)).setValue(HtmlEntry.REFERENCED_LIBRARIES, getLibrarySources2(source, unit)); |
+ HtmlEntryImpl htmlCopy = htmlEntry.writableCopy; |
+ htmlCopy.setValue(SourceEntry.LINE_INFO, new LineInfo(result.lineStarts)); |
+ htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit); |
+ htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, getLibrarySources2(source, unit)); |
+ _sourceMap[source] = htmlCopy; |
} |
} |
return unit; |
@@ -2137,47 +2390,20 @@ |
} |
} |
void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
- Source htmlSource = _sourceFactory.forUri("dart:html"); |
+ Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); |
{ |
for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) { |
Source librarySource = entry.getKey(); |
LibraryElement library = entry.getValue(); |
- DartEntryImpl dartEntry = getDartEntry(librarySource) as DartEntryImpl; |
+ DartEntry dartEntry = getDartEntry(librarySource); |
if (dartEntry != null) { |
- dartEntry.setValue(DartEntry.ELEMENT, library); |
- dartEntry.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); |
- dartEntry.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set<LibraryElement>())); |
- List<Source> unitSources = new List<Source>(); |
- unitSources.add(librarySource); |
- for (CompilationUnitElement part in library.parts) { |
- Source partSource = part.source; |
- unitSources.add(partSource); |
- } |
- dartEntry.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources)); |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ recordElementData(dartCopy, library, htmlSource); |
+ _sourceMap[librarySource] = dartCopy; |
} |
} |
} |
} |
- void recordResolutionErrors(Source source, Source librarySource, List<AnalysisError> errors, LineInfo lineInfo) { |
- { |
- DartEntryImpl dartEntry = getDartEntry(source) as DartEntryImpl; |
- if (dartEntry != null) { |
- dartEntry.setValue(SourceEntry.LINE_INFO, lineInfo); |
- dartEntry.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, errors); |
- } |
- getNotice(source).setErrors(dartEntry.allErrors, lineInfo); |
- } |
- } |
- void recordResolvedCompilationUnit(Source source, Source librarySource, CompilationUnit unit) { |
- { |
- DartEntryImpl dartEntry = getDartEntry(source) as DartEntryImpl; |
- if (dartEntry != null) { |
- dartEntry.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit); |
- dartEntry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
- getNotice(source).compilationUnit = unit; |
- } |
- } |
- } |
CompilationUnit resolveCompilationUnit(Source source2, LibraryElement library) { |
if (library == null) { |
return null; |
@@ -2209,12 +2435,14 @@ |
ResolverVisitor resolverVisitor = new ResolverVisitor.con2(libraryElement, unitSource, typeProvider, errorListener); |
unitAST.accept(resolverVisitor); |
ErrorReporter errorReporter = new ErrorReporter(errorListener, unitSource); |
- ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElement, typeProvider); |
+ ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libraryElement, typeProvider, new InheritanceManager(libraryElement)); |
unitAST.accept(errorVerifier); |
- ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter); |
+ ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, typeProvider); |
unitAST.accept(constantVerifier); |
unitAST.resolutionErrors = errorListener.errors; |
- ((dartEntry as DartEntryImpl)).setValue2(DartEntry.RESOLVED_UNIT, librarySource, unitAST); |
+ DartEntryImpl dartCopy = getDartEntry(unitSource).writableCopy; |
+ dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unitAST); |
+ _sourceMap[unitSource] = dartCopy; |
unit = unitAST; |
} |
} finally { |
@@ -2247,6 +2475,12 @@ |
return unit; |
} |
} |
+ void set analysisOptions(AnalysisOptions options2) { |
+ { |
+ this._options = options2; |
+ invalidateAllResults(); |
+ } |
+ } |
void setContents(Source source, String contents) { |
{ |
_sourceFactory.setContents(source, contents); |
@@ -2265,13 +2499,7 @@ |
} |
factory.context = this; |
_sourceFactory = factory; |
- for (SourceEntry sourceEntry in _sourceMap.values) { |
- if (sourceEntry is HtmlEntry) { |
- ((sourceEntry as HtmlEntryImpl)).setState(HtmlEntry.RESOLVED_UNIT, CacheState.INVALID); |
- } else if (sourceEntry is DartEntry) { |
- ((sourceEntry as DartEntryImpl)).invalidateAllResolutionInformation(); |
- } |
- } |
+ invalidateAllResults(); |
} |
} |
Iterable<Source> sourcesToResolve(List<Source> changedSources) { |
@@ -2283,7 +2511,38 @@ |
} |
return librarySources; |
} |
+ |
/** |
+ * Return a list of the sources that would be processed by {@link #performAnalysisTask()}. This |
+ * method is intended to be used for testing purposes only. |
+ * @return a list of the sources that would be processed by {@link #performAnalysisTask()} |
+ */ |
+ List<Source> get sourcesNeedingProcessing { |
+ List<Source> sources = new List<Source>(); |
+ { |
+ for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { |
+ SourceEntry sourceEntry = entry.getValue(); |
+ if (sourceEntry is DartEntry) { |
+ DartEntry dartEntry = sourceEntry as DartEntry; |
+ CacheState parsedUnitState = dartEntry.getState(DartEntry.PARSED_UNIT); |
+ CacheState elementState = dartEntry.getState(DartEntry.ELEMENT); |
+ if (identical(parsedUnitState, CacheState.INVALID) || identical(elementState, CacheState.INVALID)) { |
+ sources.add(entry.getKey()); |
+ } |
+ } else if (sourceEntry is HtmlEntry) { |
+ HtmlEntry htmlEntry = sourceEntry as HtmlEntry; |
+ CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT); |
+ CacheState resolvedUnitState = htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); |
+ if (identical(parsedUnitState, CacheState.INVALID) || identical(resolvedUnitState, CacheState.INVALID)) { |
+ sources.add(entry.getKey()); |
+ } |
+ } |
+ } |
+ } |
+ return sources; |
+ } |
+ |
+ /** |
* Record that the given source was just accessed for some unspecified purpose. |
* <p> |
* Note: This method must only be invoked while we are synchronized on {@link #cacheLock}. |
@@ -2299,17 +2558,22 @@ |
Source removedSource = _recentlyUsed.removeAt(0); |
SourceEntry sourceEntry = _sourceMap[removedSource]; |
if (sourceEntry is HtmlEntry) { |
- ((sourceEntry as HtmlEntryImpl)).setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); |
- ((sourceEntry as HtmlEntryImpl)).setState(HtmlEntry.RESOLVED_UNIT, CacheState.FLUSHED); |
+ HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.FLUSHED); |
+ _sourceMap[removedSource] = htmlCopy; |
} else if (sourceEntry is DartEntry) { |
- ((sourceEntry as DartEntryImpl)).setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
for (Source librarySource in getLibrariesContaining(source)) { |
- ((sourceEntry as DartEntryImpl)).setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.FLUSHED); |
+ dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.FLUSHED); |
} |
+ _sourceMap[removedSource] = dartCopy; |
} |
} |
_recentlyUsed.add(source); |
} |
+ |
/** |
* Add all of the sources contained in the given source container to the given list of sources. |
* <p> |
@@ -2324,6 +2588,7 @@ |
} |
} |
} |
+ |
/** |
* Return {@code true} if the given array of sources contains the given source. |
* @param sources the sources being searched |
@@ -2338,6 +2603,7 @@ |
} |
return false; |
} |
+ |
/** |
* Return {@code true} if the given array of sources contains any of the given target sources. |
* @param sources the sources being searched |
@@ -2352,6 +2618,7 @@ |
} |
return false; |
} |
+ |
/** |
* Create a source information object suitable for the given source. Return the source information |
* object that was created, or {@code null} if the source should not be tracked by this context. |
@@ -2371,6 +2638,7 @@ |
} |
return null; |
} |
+ |
/** |
* Disable flushing information from the cache until {@link #enableCacheRemoval()} has been |
* called. |
@@ -2378,6 +2646,7 @@ |
void disableCacheRemoval() { |
_cacheRemovalCount++; |
} |
+ |
/** |
* Re-enable flushing information from the cache. |
*/ |
@@ -2390,17 +2659,22 @@ |
Source removedSource = _recentlyUsed.removeAt(0); |
SourceEntry sourceEntry = _sourceMap[removedSource]; |
if (sourceEntry is HtmlEntry) { |
- ((sourceEntry as HtmlEntryImpl)).setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); |
- ((sourceEntry as HtmlEntryImpl)).setState(HtmlEntry.RESOLVED_UNIT, CacheState.FLUSHED); |
+ HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.FLUSHED); |
+ _sourceMap[removedSource] = htmlCopy; |
} else if (sourceEntry is DartEntry) { |
- ((sourceEntry as DartEntryImpl)).setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
for (Source librarySource in getLibrariesContaining(removedSource)) { |
- ((sourceEntry as DartEntryImpl)).setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.FLUSHED); |
+ dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.FLUSHED); |
} |
+ _sourceMap[removedSource] = dartCopy; |
} |
} |
} |
} |
+ |
/** |
* Search the compilation units that are part of the given library and return the element |
* representing the compilation unit with the given source. Return {@code null} if there is no |
@@ -2421,6 +2695,7 @@ |
} |
return null; |
} |
+ |
/** |
* Return the compilation unit information associated with the given source, or {@code null} if |
* the source is not known to this context. This method should be used to access the compilation |
@@ -2443,6 +2718,7 @@ |
} |
return null; |
} |
+ |
/** |
* Return the HTML unit information associated with the given source, or {@code null} if the |
* source is not known to this context. This method should be used to access the HTML unit |
@@ -2465,6 +2741,7 @@ |
} |
return null; |
} |
+ |
/** |
* Return the sources of libraries that are referenced in the specified HTML file. |
* @param htmlSource the source of the HTML file being analyzed |
@@ -2473,12 +2750,13 @@ |
*/ |
List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) { |
List<Source> libraries = new List<Source>(); |
- htmlUnit.accept(new RecursiveXmlVisitor_6(this, htmlSource, libraries)); |
+ htmlUnit.accept(new RecursiveXmlVisitor_7(this, htmlSource, libraries)); |
if (libraries.isEmpty) { |
return Source.EMPTY_ARRAY; |
} |
return new List.from(libraries); |
} |
+ |
/** |
* Return a change notice for the given source, creating one if one does not already exist. |
* @param source the source for which changes are being reported |
@@ -2492,7 +2770,20 @@ |
} |
return notice; |
} |
+ |
/** |
+ * Return the cache entry associated with the given source, or {@code null} if there is no entry |
+ * associated with the source. |
+ * @param source the source for which a cache entry is being sought |
+ * @return the source cache entry associated with the given source |
+ */ |
+ SourceEntry getReadableSourceEntry(Source source) { |
+ { |
+ return _sourceMap[source]; |
+ } |
+ } |
+ |
+ /** |
* Return the source information associated with the given source, or {@code null} if the source |
* is not known to this context. This method should be used to access the source information |
* rather than accessing the source map directly because sources in the SDK are implicitly part of |
@@ -2509,6 +2800,7 @@ |
} |
return sourceEntry; |
} |
+ |
/** |
* Return an array containing all of the sources known to this context that have the given kind. |
* @param kind the kind of sources to be returned |
@@ -2525,6 +2817,7 @@ |
} |
return new List.from(sources); |
} |
+ |
/** |
* Return {@code true} if the given compilation unit has a part-of directive but no library |
* directive. |
@@ -2542,6 +2835,7 @@ |
} |
return hasPartOf; |
} |
+ |
/** |
* Compute the kind of the given source. This method should only be invoked when the kind is not |
* already known. |
@@ -2559,50 +2853,59 @@ |
List<AnalysisError> errors = errorListener.getErrors2(source); |
unit.parsingErrors = errors; |
unit.lineInfo = lineInfo; |
- DartEntryImpl dartEntry = _sourceMap[source] as DartEntryImpl; |
+ DartEntryImpl dartCopy = ((_sourceMap[source] as DartEntry)).writableCopy; |
if (hasPartOfDirective(unit)) { |
- dartEntry.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); |
+ dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); |
} else { |
- dartEntry.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); |
+ dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); |
} |
- dartEntry.setValue(SourceEntry.LINE_INFO, lineInfo); |
- dartEntry.setValue(DartEntry.PARSED_UNIT, unit); |
- dartEntry.setValue(DartEntry.PARSE_ERRORS, errors); |
- return dartEntry; |
+ dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); |
+ dartCopy.setValue(DartEntry.PARSED_UNIT, unit); |
+ dartCopy.setValue(DartEntry.PARSE_ERRORS, errors); |
+ _sourceMap[source] = dartCopy; |
+ return dartCopy; |
} on AnalysisException catch (exception) { |
- DartEntryImpl dartEntry = _sourceMap[source] as DartEntryImpl; |
- dartEntry.setState(DartEntry.SOURCE_KIND, CacheState.ERROR); |
- dartEntry.setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
- dartEntry.setState(DartEntry.PARSED_UNIT, CacheState.ERROR); |
- dartEntry.setState(DartEntry.PARSE_ERRORS, CacheState.ERROR); |
- return dartEntry; |
+ DartEntryImpl dartCopy = ((_sourceMap[source] as DartEntry)).writableCopy; |
+ dartCopy.setState(DartEntry.SOURCE_KIND, CacheState.ERROR); |
+ dartCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.ERROR); |
+ dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.ERROR); |
+ _sourceMap[source] = dartCopy; |
+ return dartCopy; |
} |
} |
- CompilationUnit internalParseCompilationUnit(DartEntryImpl dartEntry, Source source) { |
+ CompilationUnit internalParseCompilationUnit(DartEntryImpl dartCopy, Source source) { |
accessed(source); |
- RecordingErrorListener errorListener = new RecordingErrorListener(); |
- AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorListener); |
- Parser parser = new Parser(source, errorListener); |
- CompilationUnit unit = parser.parseCompilationUnit(scanResult._token); |
- LineInfo lineInfo = new LineInfo(scanResult._lineStarts); |
- List<AnalysisError> errors = errorListener.getErrors2(source); |
- unit.parsingErrors = errors; |
- unit.lineInfo = lineInfo; |
- if (identical(dartEntry.getState(DartEntry.SOURCE_KIND), CacheState.INVALID)) { |
- if (hasPartOfDirective(unit)) { |
- dartEntry.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); |
- } else { |
- dartEntry.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); |
+ try { |
+ RecordingErrorListener errorListener = new RecordingErrorListener(); |
+ AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorListener); |
+ Parser parser = new Parser(source, errorListener); |
+ CompilationUnit unit = parser.parseCompilationUnit(scanResult._token); |
+ LineInfo lineInfo = new LineInfo(scanResult._lineStarts); |
+ List<AnalysisError> errors = errorListener.getErrors2(source); |
+ unit.parsingErrors = errors; |
+ unit.lineInfo = lineInfo; |
+ if (identical(dartCopy.getState(DartEntry.SOURCE_KIND), CacheState.INVALID)) { |
+ if (hasPartOfDirective(unit)) { |
+ dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); |
+ } else { |
+ dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); |
+ } |
} |
+ dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); |
+ dartCopy.setValue(DartEntry.PARSED_UNIT, unit); |
+ dartCopy.setValue(DartEntry.PARSE_ERRORS, errors); |
+ return unit; |
+ } on AnalysisException catch (exception) { |
+ dartCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR); |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.ERROR); |
+ dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.ERROR); |
+ throw exception; |
} |
- dartEntry.setValue(SourceEntry.LINE_INFO, lineInfo); |
- dartEntry.setValue(DartEntry.PARSED_UNIT, unit); |
- dartEntry.setValue(DartEntry.PARSE_ERRORS, errors); |
- return unit; |
} |
AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListener errorListener) { |
AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult(); |
- Source_ContentReceiver receiver = new Source_ContentReceiver_7(source, errorListener, result); |
+ Source_ContentReceiver receiver = new Source_ContentReceiver_8(source, errorListener, result); |
try { |
source.getContents(receiver); |
} catch (exception) { |
@@ -2610,22 +2913,51 @@ |
} |
return result; |
} |
+ |
/** |
+ * Invalidate all of the results computed by this context. |
+ * <p> |
+ * <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. |
+ */ |
+ void invalidateAllResults() { |
+ for (MapEntry<Source, SourceEntry> mapEntry in getMapEntrySet(_sourceMap)) { |
+ SourceEntry sourceEntry = mapEntry.getValue(); |
+ if (sourceEntry is HtmlEntry) { |
+ HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.INVALID); |
+ mapEntry.setValue(htmlCopy); |
+ } else if (sourceEntry is DartEntry) { |
+ DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; |
+ dartCopy.invalidateAllResolutionInformation(); |
+ mapEntry.setValue(dartCopy); |
+ } |
+ } |
+ } |
+ |
+ /** |
* In response to a change to at least one of the compilation units in the given library, |
* invalidate any results that are dependent on the result of resolving that library. |
* @param librarySource the source of the library being invalidated |
- * @param libraryEntry the cache entry for the library being invalidated |
*/ |
- void invalidateLibraryResolution(Source librarySource, DartEntryImpl libraryEntry) { |
+ void invalidateLibraryResolution(Source librarySource) { |
+ DartEntry libraryEntry = getDartEntry(librarySource); |
if (libraryEntry != null) { |
- for (Source unitSource in libraryEntry.getValue(DartEntry.INCLUDED_PARTS)) { |
- DartEntryImpl partEntry = getDartEntry(unitSource) as DartEntryImpl; |
- partEntry.invalidateAllResolutionInformation(); |
+ List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PARTS); |
+ DartEntryImpl libraryCopy = libraryEntry.writableCopy; |
+ libraryCopy.invalidateAllResolutionInformation(); |
+ libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID); |
+ _sourceMap[librarySource] = libraryCopy; |
+ for (Source unitSource in includedParts) { |
+ DartEntry partEntry = getDartEntry(unitSource); |
+ if (partEntry != null) { |
+ DartEntryImpl dartCopy = partEntry.writableCopy; |
+ dartCopy.invalidateAllResolutionInformation(); |
+ _sourceMap[unitSource] = dartCopy; |
+ } |
} |
- libraryEntry.invalidateAllResolutionInformation(); |
- libraryEntry.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID); |
} |
} |
+ |
/** |
* Return {@code true} if this library is, or depends on, dart:html. |
* @param library the library being tested |
@@ -2653,6 +2985,7 @@ |
} |
return false; |
} |
+ |
/** |
* Perform a single analysis task. |
* <p> |
@@ -2669,7 +3002,9 @@ |
try { |
parseCompilationUnit(entry.getKey()); |
} on AnalysisException catch (exception) { |
- ((dartEntry as DartEntryImpl)).setState(DartEntry.PARSED_UNIT, CacheState.ERROR); |
+ DartEntryImpl dartCopy = ((entry.getValue() as DartEntry)).writableCopy; |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.ERROR); |
+ entry.setValue(dartCopy); |
AnalysisEngine.instance.logger.logError2("Could not parse ${entry.getKey().fullName}", exception); |
} |
return true; |
@@ -2681,7 +3016,9 @@ |
try { |
parseHtmlUnit(entry.getKey()); |
} on AnalysisException catch (exception) { |
- ((htmlEntry as HtmlEntryImpl)).setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); |
+ HtmlEntryImpl htmlCopy = ((entry.getValue() as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); |
+ entry.setValue(htmlCopy); |
AnalysisEngine.instance.logger.logError2("Could not parse ${entry.getKey().fullName}", exception); |
} |
return true; |
@@ -2697,7 +3034,9 @@ |
try { |
computeLibraryElement(entry.getKey()); |
} on AnalysisException catch (exception) { |
- ((dartEntry as DartEntryImpl)).setState(DartEntry.ELEMENT, CacheState.ERROR); |
+ DartEntryImpl dartCopy = ((entry.getValue() as DartEntry)).writableCopy; |
+ dartCopy.setState(DartEntry.ELEMENT, CacheState.ERROR); |
+ entry.setValue(dartCopy); |
AnalysisEngine.instance.logger.logError2("Could not resolve ${entry.getKey().fullName}", exception); |
} |
return true; |
@@ -2709,7 +3048,9 @@ |
try { |
resolveHtmlUnit(entry.getKey()); |
} on AnalysisException catch (exception) { |
- ((htmlEntry as HtmlEntryImpl)).setState(HtmlEntry.RESOLVED_UNIT, CacheState.ERROR); |
+ HtmlEntryImpl htmlCopy = ((entry.getValue() as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.ERROR); |
+ entry.setValue(htmlCopy); |
AnalysisEngine.instance.logger.logError2("Could not resolve ${entry.getKey().fullName}", exception); |
} |
return true; |
@@ -2718,6 +3059,76 @@ |
} |
return false; |
} |
+ |
+ /** |
+ * Given a cache entry and a library element, record the library element and other information |
+ * gleaned from the element in the cache entry. |
+ * @param dartCopy the cache entry in which data is to be recorded |
+ * @param library the library element used to record information |
+ * @param htmlSource the source for the HTML library |
+ */ |
+ void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) { |
+ dartCopy.setValue(DartEntry.ELEMENT, library); |
+ dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); |
+ dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set<LibraryElement>())); |
+ List<Source> unitSources = new List<Source>(); |
+ unitSources.add(library.definingCompilationUnit.source); |
+ for (CompilationUnitElement part in library.parts) { |
+ Source partSource = part.source; |
+ unitSources.add(partSource); |
+ } |
+ dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources)); |
+ } |
+ |
+ /** |
+ * Record the result of using the given resolver to resolve one or more libraries. |
+ * @param resolver the resolver that has the needed results |
+ * @throws AnalysisException if the results cannot be retrieved for some reason |
+ */ |
+ void recordResolutionResults(LibraryResolver resolver) { |
+ Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); |
+ RecordingErrorListener errorListener2 = resolver.errorListener; |
+ for (Library library in resolver.resolvedLibraries) { |
+ Source librarySource2 = library.librarySource; |
+ Set<Source> referencedLibraries = new Set<Source>(); |
+ for (Library referencedLibrary in library.exports) { |
+ javaSetAdd(referencedLibraries, referencedLibrary.librarySource); |
+ } |
+ for (Library referencedLibrary in library.imports) { |
+ javaSetAdd(referencedLibraries, referencedLibrary.librarySource); |
+ } |
+ for (Source source in library.compilationUnitSources) { |
+ CompilationUnit unit = library.getAST(source); |
+ List<AnalysisError> errors = errorListener2.getErrors2(source); |
+ unit.resolutionErrors = errors; |
+ LineInfo lineInfo2 = unit.lineInfo; |
+ { |
+ DartEntry dartEntry = getDartEntry(source); |
+ if (dartEntry != null) { |
+ DartEntryImpl dartCopy = dartEntry.writableCopy; |
+ dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo2); |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
+ dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource2, unit); |
+ dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource2, errors); |
+ if (identical(source, librarySource2)) { |
+ recordElementData(dartCopy, library.libraryElement, htmlSource); |
+ List<Source> libraries; |
+ if (referencedLibraries.isEmpty) { |
+ libraries = Source.EMPTY_ARRAY; |
+ } else { |
+ libraries = new List.from(referencedLibraries); |
+ } |
+ dartCopy.setValue(DartEntry.REFERENCED_LIBRARIES, libraries); |
+ } |
+ _sourceMap[source] = dartCopy; |
+ ChangeNoticeImpl notice = getNotice(source); |
+ notice.compilationUnit = unit; |
+ notice.setErrors(dartCopy.allErrors, lineInfo2); |
+ } |
+ } |
+ } |
+ } |
+ } |
HtmlScanResult scanHtml(Source source) { |
HtmlScanner scanner = new HtmlScanner(source); |
try { |
@@ -2727,6 +3138,7 @@ |
} |
return scanner.result; |
} |
+ |
/** |
* Create an entry for the newly added source. Return {@code true} if the new source is a Dart |
* file. |
@@ -2742,6 +3154,7 @@ |
} |
return sourceEntry is DartEntry; |
} |
+ |
/** |
* <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. |
* @param source the source that has been changed |
@@ -2749,27 +3162,28 @@ |
void sourceChanged(Source source) { |
SourceEntry sourceEntry = _sourceMap[source]; |
if (sourceEntry is HtmlEntry) { |
- HtmlEntryImpl htmlEntry = sourceEntry as HtmlEntryImpl; |
- htmlEntry.setState(HtmlEntry.ELEMENT, CacheState.INVALID); |
- htmlEntry.setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
- htmlEntry.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID); |
- htmlEntry.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID); |
- htmlEntry.setState(HtmlEntry.RESOLVED_UNIT, CacheState.INVALID); |
+ HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; |
+ htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID); |
+ htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
+ htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID); |
+ htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID); |
+ htmlCopy.setState(HtmlEntry.RESOLVED_UNIT, CacheState.INVALID); |
+ _sourceMap[source] = htmlCopy; |
} else if (sourceEntry is DartEntry) { |
- DartEntryImpl dartEntry = sourceEntry as DartEntryImpl; |
List<Source> containingLibraries = getLibrariesContaining(source); |
- invalidateLibraryResolution(source, dartEntry); |
- dartEntry.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID); |
- dartEntry.setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
- dartEntry.setState(DartEntry.PARSE_ERRORS, CacheState.INVALID); |
- dartEntry.setState(DartEntry.PARSED_UNIT, CacheState.INVALID); |
- dartEntry.setState(DartEntry.SOURCE_KIND, CacheState.INVALID); |
+ DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; |
+ dartCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID); |
+ dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.INVALID); |
+ dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.INVALID); |
+ dartCopy.setState(DartEntry.SOURCE_KIND, CacheState.INVALID); |
+ _sourceMap[source] = dartCopy; |
+ invalidateLibraryResolution(source); |
for (Source librarySource in containingLibraries) { |
- DartEntryImpl libraryEntry = getDartEntry(librarySource) as DartEntryImpl; |
- invalidateLibraryResolution(librarySource, libraryEntry); |
+ invalidateLibraryResolution(librarySource); |
} |
} |
} |
+ |
/** |
* <b>Note:</b> This method must only be invoked while we are synchronized on {@link #cacheLock}. |
* @param source the source that has been deleted |
@@ -2777,39 +3191,44 @@ |
void sourceRemoved(Source source) { |
DartEntry dartEntry = getDartEntry(source); |
if (dartEntry != null) { |
+ Set<Source> libraries = new Set<Source>(); |
for (Source librarySource in getLibrariesContaining(source)) { |
- DartEntryImpl libraryEntry = getDartEntry(librarySource) as DartEntryImpl; |
- invalidateLibraryResolution(librarySource, libraryEntry); |
+ javaSetAdd(libraries, librarySource); |
+ for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) { |
+ javaSetAdd(libraries, dependentLibrary); |
+ } |
} |
+ for (Source librarySource in libraries) { |
+ invalidateLibraryResolution(librarySource); |
+ } |
} |
_sourceMap.remove(source); |
} |
} |
+ |
/** |
* Instances of the class {@code ScanResult} represent the results of scanning a source. |
*/ |
class AnalysisContextImpl_ScanResult { |
+ |
/** |
* The time at which the contents of the source were last set. |
*/ |
int _modificationTime = 0; |
+ |
/** |
* The first token in the token stream. |
*/ |
Token _token; |
+ |
/** |
* The line start information that was produced. |
*/ |
List<int> _lineStarts; |
- /** |
- * Initialize a newly created result object to be empty. |
- */ |
- AnalysisContextImpl_ScanResult() : super() { |
- } |
} |
-class Source_ContentReceiver_5 implements Source_ContentReceiver { |
+class Source_ContentReceiver_6 implements Source_ContentReceiver { |
List<CharSequence> contentHolder; |
- Source_ContentReceiver_5(this.contentHolder); |
+ Source_ContentReceiver_6(this.contentHolder); |
void accept(CharBuffer contents, int modificationTime) { |
contentHolder[0] = contents; |
} |
@@ -2817,11 +3236,11 @@ |
contentHolder[0] = new CharSequence(contents); |
} |
} |
-class RecursiveXmlVisitor_6 extends RecursiveXmlVisitor<Object> { |
+class RecursiveXmlVisitor_7 extends RecursiveXmlVisitor<Object> { |
final AnalysisContextImpl AnalysisContextImpl_this; |
Source htmlSource; |
List<Source> libraries; |
- RecursiveXmlVisitor_6(this.AnalysisContextImpl_this, this.htmlSource, this.libraries) : super(); |
+ RecursiveXmlVisitor_7(this.AnalysisContextImpl_this, this.htmlSource, this.libraries) : super(); |
Object visitXmlTagNode(XmlTagNode node) { |
if (javaStringEqualsIgnoreCase(node.tag.lexeme, AnalysisContextImpl._TAG_SCRIPT)) { |
for (XmlAttributeNode attribute in node.attributes) { |
@@ -2844,11 +3263,11 @@ |
return super.visitXmlTagNode(node); |
} |
} |
-class Source_ContentReceiver_7 implements Source_ContentReceiver { |
+class Source_ContentReceiver_8 implements Source_ContentReceiver { |
Source source; |
AnalysisErrorListener errorListener; |
AnalysisContextImpl_ScanResult result; |
- Source_ContentReceiver_7(this.source, this.errorListener, this.result); |
+ Source_ContentReceiver_8(this.source, this.errorListener, this.result); |
void accept(CharBuffer contents, int modificationTime2) { |
CharBufferScanner scanner = new CharBufferScanner(source, contents, errorListener); |
result._modificationTime = modificationTime2; |
@@ -2862,19 +3281,23 @@ |
result._lineStarts = scanner.lineStarts; |
} |
} |
+ |
/** |
* Instances of the class {@code AnalysisErrorInfoImpl} represent the analysis errors and line info |
* associated with a source. |
*/ |
class AnalysisErrorInfoImpl implements AnalysisErrorInfo { |
+ |
/** |
* The analysis errors associated with a source, or {@code null} if there are no errors. |
*/ |
List<AnalysisError> _errors; |
+ |
/** |
* The line information associated with the errors, or {@code null} if there are no errors. |
*/ |
LineInfo _lineInfo; |
+ |
/** |
* Initialize an newly created error info with the errors and line information |
* @param errors the errors as a result of analysis |
@@ -2884,11 +3307,13 @@ |
this._errors = errors; |
this._lineInfo = lineInfo; |
} |
+ |
/** |
* Return the errors of analysis, or {@code null} if there were no errors. |
* @return the errors as a result of the analysis |
*/ |
List<AnalysisError> get errors => _errors; |
+ |
/** |
* Return the line information associated with the errors, or {@code null} if there were no |
* errors. |
@@ -2896,10 +3321,41 @@ |
*/ |
LineInfo get lineInfo => _lineInfo; |
} |
+ |
/** |
+ * Instances of the class {@code AnalysisOptions} represent a set of analysis options used to |
+ * control the behavior of an analysis context. |
+ */ |
+class AnalysisOptionsImpl implements AnalysisOptions { |
+ |
+ /** |
+ * A flag indicating whether analysis is to use strict mode. In strict mode, error reporting is |
+ * based exclusively on the static type information. |
+ */ |
+ bool _strictMode = false; |
+ |
+ /** |
+ * Return {@code true} if analysis is to use strict mode. In strict mode, error reporting is based |
+ * exclusively on the static type information. |
+ * @return {@code true} if analysis is to use strict mode |
+ */ |
+ bool get strictMode => _strictMode; |
+ |
+ /** |
+ * Set whether analysis is to use strict mode to the given value. In strict mode, error reporting |
+ * is based exclusively on the static type information. |
+ * @param isStrict {@code true} if analysis is to use strict mode |
+ */ |
+ void set strictMode(bool isStrict) { |
+ _strictMode = isStrict; |
+ } |
+} |
+ |
+/** |
* The enumeration {@code CacheState} defines the possible states of cached data. |
*/ |
class CacheState implements Comparable<CacheState> { |
+ |
/** |
* The data is not in the cache and the last time an attempt was made to compute the data an |
* exception occurred, making it pointless to attempt. |
@@ -2910,6 +3366,7 @@ |
* </ul> |
*/ |
static final CacheState ERROR = new CacheState('ERROR', 0); |
+ |
/** |
* The data is not in the cache because it was flushed from the cache in order to control memory |
* usage. If the data is recomputed, results do not need to be reported. |
@@ -2921,6 +3378,7 @@ |
* </ul> |
*/ |
static final CacheState FLUSHED = new CacheState('FLUSHED', 1); |
+ |
/** |
* The data might or might not be in the cache but is in the process of being recomputed. |
* <p> |
@@ -2931,6 +3389,7 @@ |
* </ul> |
*/ |
static final CacheState IN_PROCESS = new CacheState('IN_PROCESS', 2); |
+ |
/** |
* The data is not in the cache and needs to be recomputed so that results can be reported. |
* <p> |
@@ -2940,6 +3399,7 @@ |
* </ul> |
*/ |
static final CacheState INVALID = new CacheState('INVALID', 3); |
+ |
/** |
* The data is in the cache and up-to-date. |
* <p> |
@@ -2951,42 +3411,52 @@ |
*/ |
static final CacheState VALID = new CacheState('VALID', 4); |
static final List<CacheState> values = [ERROR, FLUSHED, IN_PROCESS, INVALID, VALID]; |
- final String __name; |
- final int __ordinal; |
- int get ordinal => __ordinal; |
- CacheState(this.__name, this.__ordinal) { |
+ |
+ /// The name of this enum constant, as declared in the enum declaration. |
+ final String name; |
+ |
+ /// The position in the enum declaration. |
+ final int ordinal; |
+ CacheState(this.name, this.ordinal) { |
} |
- int compareTo(CacheState other) => __ordinal - other.__ordinal; |
- String toString() => __name; |
+ int compareTo(CacheState other) => ordinal - other.ordinal; |
+ String toString() => name; |
} |
+ |
/** |
* Instances of the class {@code ChangeNoticeImpl} represent a change to the analysis results |
* associated with a given source. |
* @coverage dart.engine |
*/ |
class ChangeNoticeImpl implements ChangeNotice { |
+ |
/** |
* The source for which the result is being reported. |
*/ |
Source _source; |
+ |
/** |
* The fully resolved AST that changed as a result of the analysis, or {@code null} if the AST was |
* not changed. |
*/ |
CompilationUnit _compilationUnit; |
+ |
/** |
* The errors that changed as a result of the analysis, or {@code null} if errors were not |
* changed. |
*/ |
List<AnalysisError> _errors; |
+ |
/** |
* The line information associated with the source, or {@code null} if errors were not changed. |
*/ |
LineInfo _lineInfo; |
+ |
/** |
* An empty array of change notices. |
*/ |
static List<ChangeNoticeImpl> EMPTY_ARRAY = new List<ChangeNoticeImpl>(0); |
+ |
/** |
* Initialize a newly created notice associated with the given source. |
* @param source the source for which the change is being reported |
@@ -2994,29 +3464,34 @@ |
ChangeNoticeImpl(Source source) { |
this._source = source; |
} |
+ |
/** |
* Return the fully resolved AST that changed as a result of the analysis, or {@code null} if the |
* AST was not changed. |
* @return the fully resolved AST that changed as a result of the analysis |
*/ |
CompilationUnit get compilationUnit => _compilationUnit; |
+ |
/** |
* Return the errors that changed as a result of the analysis, or {@code null} if errors were not |
* changed. |
* @return the errors that changed as a result of the analysis |
*/ |
List<AnalysisError> get errors => _errors; |
+ |
/** |
* Return the line information associated with the source, or {@code null} if errors were not |
* changed. |
* @return the line information associated with the source |
*/ |
LineInfo get lineInfo => _lineInfo; |
+ |
/** |
* Return the source for which the result is being reported. |
* @return the source for which the result is being reported |
*/ |
Source get source => _source; |
+ |
/** |
* Set the fully resolved AST that changed as a result of the analysis to the given AST. |
* @param compilationUnit the fully resolved AST that changed as a result of the analysis |
@@ -3024,6 +3499,7 @@ |
void set compilationUnit(CompilationUnit compilationUnit2) { |
this._compilationUnit = compilationUnit2; |
} |
+ |
/** |
* Set the errors that changed as a result of the analysis to the given errors and set the line |
* information to the given line information. |
@@ -3035,12 +3511,14 @@ |
this._lineInfo = lineInfo2; |
} |
} |
+ |
/** |
* Instances of the class {@code DelegatingAnalysisContextImpl} extend {@link AnalysisContextImplanalysis context} to delegate sources to the appropriate analysis context. For instance, if the |
* source is in a system library then the analysis context from the {@link DartSdk} is used. |
* @coverage dart.engine |
*/ |
class DelegatingAnalysisContextImpl extends AnalysisContextImpl { |
+ |
/** |
* This references the {@link InternalAnalysisContext} held onto by the {@link DartSdk} which is |
* used (instead of this {@link AnalysisContext}) for SDK sources. This field is set when |
@@ -3048,11 +3526,6 @@ |
* will be such a resolver. |
*/ |
InternalAnalysisContext _sdkAnalysisContext; |
- /** |
- * Initialize a newly created delegating analysis context. |
- */ |
- DelegatingAnalysisContextImpl() : super() { |
- } |
void addSourceInfo(Source source, SourceEntry info) { |
if (source.isInSystemLibrary()) { |
_sdkAnalysisContext.addSourceInfo(source, info); |
@@ -3137,6 +3610,13 @@ |
return super.getLibrariesContaining(source); |
} |
} |
+ List<Source> getLibrariesDependingOn(Source librarySource) { |
+ if (librarySource.isInSystemLibrary()) { |
+ return _sdkAnalysisContext.getLibrariesDependingOn(librarySource); |
+ } else { |
+ return super.getLibrariesDependingOn(librarySource); |
+ } |
+ } |
LibraryElement getLibraryElement(Source source) { |
if (source.isInSystemLibrary()) { |
return _sdkAnalysisContext.getLibraryElement(source); |
@@ -3220,20 +3700,6 @@ |
super.recordLibraryElements(elementMap); |
} |
} |
- void recordResolutionErrors(Source source, Source librarySource, List<AnalysisError> errors, LineInfo lineInfo) { |
- if (source.isInSystemLibrary()) { |
- _sdkAnalysisContext.recordResolutionErrors(source, librarySource, errors, lineInfo); |
- } else { |
- super.recordResolutionErrors(source, librarySource, errors, lineInfo); |
- } |
- } |
- void recordResolvedCompilationUnit(Source source, Source librarySource, CompilationUnit unit) { |
- if (source.isInSystemLibrary()) { |
- _sdkAnalysisContext.recordResolvedCompilationUnit(source, librarySource, unit); |
- } else { |
- super.recordResolvedCompilationUnit(source, librarySource, unit); |
- } |
- } |
CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) { |
if (source.isInSystemLibrary()) { |
return _sdkAnalysisContext.resolveCompilationUnit(source, library); |
@@ -3276,12 +3742,14 @@ |
} |
} |
} |
+ |
/** |
* Instances of the class {@code InstrumentedAnalysisContextImpl} implement an{@link AnalysisContext analysis context} by recording instrumentation data and delegating to |
* another analysis context to do the non-instrumentation work. |
* @coverage dart.engine |
*/ |
class InstrumentedAnalysisContextImpl implements InternalAnalysisContext { |
+ |
/** |
* Record an exception that was thrown during analysis. |
* @param instrumentation the instrumentation builder being used to record the exception |
@@ -3290,32 +3758,36 @@ |
static void recordAnalysisException(InstrumentationBuilder instrumentation, AnalysisException exception) { |
instrumentation.record(exception); |
} |
+ |
/** |
* The unique identifier used to identify this analysis context in the instrumentation data. |
*/ |
String _contextId = UUID.randomUUID().toString(); |
+ |
/** |
* The analysis context to which all of the non-instrumentation work is delegated. |
*/ |
InternalAnalysisContext _basis; |
+ |
/** |
* Create a new {@link InstrumentedAnalysisContextImpl} which wraps a new{@link AnalysisContextImpl} as the basis context. |
*/ |
InstrumentedAnalysisContextImpl() { |
- _jtd_constructor_178_impl(); |
+ _jtd_constructor_182_impl(); |
} |
- _jtd_constructor_178_impl() { |
- _jtd_constructor_179_impl(new AnalysisContextImpl()); |
+ _jtd_constructor_182_impl() { |
+ _jtd_constructor_183_impl(new AnalysisContextImpl()); |
} |
+ |
/** |
* Create a new {@link InstrumentedAnalysisContextImpl} with a specified basis context, aka the |
* context to wrap and instrument. |
* @param context some {@link InstrumentedAnalysisContext} to wrap and instrument |
*/ |
InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) { |
- _jtd_constructor_179_impl(context); |
+ _jtd_constructor_183_impl(context); |
} |
- _jtd_constructor_179_impl(InternalAnalysisContext context) { |
+ _jtd_constructor_183_impl(InternalAnalysisContext context) { |
_basis = context; |
} |
void addSourceInfo(Source source, SourceEntry info) { |
@@ -3408,6 +3880,16 @@ |
} |
} |
InternalAnalysisContext extractContextInto(SourceContainer container, InternalAnalysisContext newContext) => _basis.extractContextInto(container, newContext); |
+ AnalysisOptions get analysisOptions { |
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getAnalysisOptions"); |
+ try { |
+ instrumentation.metric3("contextId", _contextId); |
+ return _basis.analysisOptions; |
+ } finally { |
+ instrumentation.log(); |
+ } |
+ } |
+ |
/** |
* @return the underlying {@link AnalysisContext}. |
*/ |
@@ -3517,6 +3999,19 @@ |
instrumentation.log(); |
} |
} |
+ List<Source> getLibrariesDependingOn(Source librarySource) { |
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLibrariesDependingOn"); |
+ try { |
+ instrumentation.metric3("contextId", _contextId); |
+ List<Source> ret = _basis.getLibrariesDependingOn(librarySource); |
+ if (ret != null) { |
+ instrumentation.metric2("Source-count", ret.length); |
+ } |
+ return ret; |
+ } finally { |
+ instrumentation.log(); |
+ } |
+ } |
LibraryElement getLibraryElement(Source source) { |
InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLibraryElement"); |
try { |
@@ -3647,12 +4142,6 @@ |
void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
_basis.recordLibraryElements(elementMap); |
} |
- void recordResolutionErrors(Source source, Source librarySource, List<AnalysisError> errors, LineInfo lineInfo) { |
- _basis.recordResolutionErrors(source, librarySource, errors, lineInfo); |
- } |
- void recordResolvedCompilationUnit(Source source, Source librarySource, CompilationUnit unit) { |
- _basis.recordResolvedCompilationUnit(source, librarySource, unit); |
- } |
CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement library) { |
InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-resolveCompilationUnit"); |
try { |
@@ -3689,6 +4178,15 @@ |
instrumentation.log(); |
} |
} |
+ void set analysisOptions(AnalysisOptions options) { |
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-setAnalysisOptions"); |
+ try { |
+ instrumentation.metric3("contextId", _contextId); |
+ _basis.analysisOptions = options; |
+ } finally { |
+ instrumentation.log(); |
+ } |
+ } |
void setContents(Source source, String contents) { |
InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-setContents"); |
try { |
@@ -3717,17 +4215,20 @@ |
} |
} |
} |
+ |
/** |
* The interface {@code InternalAnalysisContext} defines additional behavior for an analysis context |
* that is required by internal users of the context. |
*/ |
abstract class InternalAnalysisContext implements AnalysisContext { |
+ |
/** |
* Add the given source with the given information to this context. |
* @param source the source to be added |
* @param info the information about the source |
*/ |
void addSourceInfo(Source source, SourceEntry info); |
+ |
/** |
* Return an AST structure corresponding to the given source, but ensure that the structure has |
* not already been resolved and will not be resolved by any other threads or in any other |
@@ -3737,6 +4238,7 @@ |
* @throws AnalysisException if the analysis could not be performed |
*/ |
CompilationUnit computeResolvableCompilationUnit(Source source); |
+ |
/** |
* Initialize the specified context by removing the specified sources from the receiver and adding |
* them to the specified context. |
@@ -3746,6 +4248,7 @@ |
* @return the analysis context that was initialized |
*/ |
InternalAnalysisContext extractContextInto(SourceContainer container, InternalAnalysisContext newContext); |
+ |
/** |
* Return a namespace containing mappings for all of the public names defined by the given |
* library. |
@@ -3753,6 +4256,7 @@ |
* @return the public namespace of the given library |
*/ |
Namespace getPublicNamespace(LibraryElement library); |
+ |
/** |
* Return a namespace containing mappings for all of the public names defined by the library |
* defined by the given source. |
@@ -3761,6 +4265,7 @@ |
* @throws AnalysisException if the public namespace could not be computed |
*/ |
Namespace getPublicNamespace2(Source source); |
+ |
/** |
* Given a table mapping the source for the libraries represented by the corresponding elements to |
* the elements representing the libraries, record those mappings. |
@@ -3768,25 +4273,8 @@ |
* the elements representing the libraries |
*/ |
void recordLibraryElements(Map<Source, LibraryElement> elementMap); |
- /** |
- * Give the resolution errors and line info associated with the given source, add the information |
- * to the cache. |
- * @param source the source with which the information is associated |
- * @param librarySource the source of the defining compilation unit of the library in which the |
- * source was resolved |
- * @param errors the resolution errors associated with the source |
- * @param lineInfo the line information associated with the source |
- */ |
- void recordResolutionErrors(Source source, Source librarySource, List<AnalysisError> errors, LineInfo lineInfo); |
- /** |
- * Give the resolved compilation unit associated with the given source, add the unit to the cache. |
- * @param source the source with which the unit is associated |
- * @param librarySource the source of the defining compilation unit of the library in which the |
- * source was resolved |
- * @param unit the compilation unit associated with the source |
- */ |
- void recordResolvedCompilationUnit(Source source, Source librarySource, CompilationUnit unit); |
} |
+ |
/** |
* Instances of the class {@code RecordingErrorListener} implement an error listener that will |
* record the errors that are reported to it in a way that is appropriate for caching those errors |
@@ -3794,11 +4282,23 @@ |
* @coverage dart.engine |
*/ |
class RecordingErrorListener implements AnalysisErrorListener { |
+ |
/** |
* A HashMap of lists containing the errors that were collected, keyed by each {@link Source}. |
*/ |
Map<Source, List<AnalysisError>> _errors = new Map<Source, List<AnalysisError>>(); |
+ |
/** |
+ * Add all of the errors recorded by the given listener to this listener. |
+ * @param listener the listener that has recorded the errors to be added |
+ */ |
+ void addAll(RecordingErrorListener listener) { |
+ for (AnalysisError error in listener.errors) { |
+ onError(error); |
+ } |
+ } |
+ |
+ /** |
* Answer the errors collected by the listener. |
* @return an array of errors (not {@code null}, contains no {@code null}s) |
*/ |
@@ -3813,6 +4313,7 @@ |
} |
return new List.from(resultList); |
} |
+ |
/** |
* Answer the errors collected by the listener for some passed {@link Source}. |
* @param source some {@link Source} for which the caller wants the set of {@link AnalysisError}s |
@@ -3837,6 +4338,7 @@ |
errorsForSource.add(event); |
} |
} |
+ |
/** |
* Instances of the class {@code ResolutionEraser} remove any resolution information from an AST |
* structure when used to visit that structure. |
@@ -3908,6 +4410,7 @@ |
return super.visitSuperConstructorInvocation(node); |
} |
} |
+ |
/** |
* The interface {@code Logger} defines the behavior of objects that can be used to receive |
* information about errors within the analysis engine. Implementations usually write this |
@@ -3917,28 +4420,33 @@ |
*/ |
abstract class Logger { |
static Logger NULL = new Logger_NullLogger(); |
+ |
/** |
* Log the given message as an error. |
* @param message an explanation of why the error occurred or what it means |
*/ |
void logError(String message); |
+ |
/** |
* Log the given exception as one representing an error. |
* @param message an explanation of why the error occurred or what it means |
* @param exception the exception being logged |
*/ |
void logError2(String message, Exception exception); |
+ |
/** |
* Log the given exception as one representing an error. |
* @param exception the exception being logged |
*/ |
void logError3(Exception exception); |
+ |
/** |
* Log the given informational message. |
* @param message an explanation of why the error occurred or what it means |
* @param exception the exception being logged |
*/ |
void logInformation(String message); |
+ |
/** |
* Log the given exception as one representing an informational message. |
* @param message an explanation of why the error occurred or what it means |
@@ -3946,6 +4454,7 @@ |
*/ |
void logInformation2(String message, Exception exception); |
} |
+ |
/** |
* Implementation of {@link Logger} that does nothing. |
*/ |