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

Unified Diff: pkg/analyzer_experimental/lib/src/generated/engine.dart

Issue 14308011: New Analysis Engine snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_experimental/lib/src/generated/engine.dart
diff --git a/pkg/analyzer_experimental/lib/src/generated/engine.dart b/pkg/analyzer_experimental/lib/src/generated/engine.dart
index 6b0bdad7e69009ed3d8f8e2267174b01f1b11bc4..428c187edb52e50cc3fe5f8a76667745f7da0b9c 100644
--- a/pkg/analyzer_experimental/lib/src/generated/engine.dart
+++ b/pkg/analyzer_experimental/lib/src/generated/engine.dart
@@ -3,17 +3,20 @@
library engine;
+import 'dart:collection' show HasNextIterator;
+import 'dart:uri' show Uri;
import 'java_core.dart';
import 'java_engine.dart';
-import 'dart:collection' show HasNextIterator;
+import 'instrumentation.dart';
import 'error.dart';
import 'source.dart';
import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
-import 'ast.dart' show CompilationUnit, Directive, PartOfDirective;
+import 'ast.dart';
import 'parser.dart' show Parser;
+import 'sdk.dart' show DartSdk;
import 'element.dart';
-import 'resolver.dart' show Namespace, NamespaceBuilder, LibraryResolver, HtmlUnitBuilder;
-import 'html.dart' show XmlTagNode, XmlAttributeNode, SimpleXmlVisitor, HtmlScanner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit;
+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
@@ -78,7 +81,13 @@ class AnalysisEngine {
* Create a new context in which analysis can be performed.
* @return the analysis context that was created
*/
- AnalysisContext createAnalysisContext() => new AnalysisContextImpl();
+ AnalysisContext createAnalysisContext() {
+ if (Instrumentation.isNullLogger()) {
+ return new DelegatingAnalysisContextImpl();
+ } else {
+ 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
@@ -207,14 +216,15 @@ abstract class AnalysisContext {
*/
Element getElement(ElementLocation location);
/**
- * Return an array containing all of the errors associated with the given source. The array will
- * be empty if the source is not known to this context or if there are no errors in the source.
- * The errors contained in the array can be incomplete.
+ * 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
+ * to this context or if there are no errors in the source. The errors contained in the array can
+ * be incomplete.
* @param source the source whose errors are to be returned
- * @return all of the errors associated with the given source
+ * @return all of the errors associated with the given source and the line info
* @see #computeErrors(Source)
*/
- List<AnalysisError> getErrors(Source 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.
@@ -298,6 +308,23 @@ abstract class AnalysisContext {
*/
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
+ * @param library the library containing the compilation unit
+ * @return a fully resolved AST for the compilation unit
+ * @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
+ * @param librarySource the source of the defining compilation unit of the library containing the
+ * compilation unit
+ * @return a fully resolved AST for the compilation unit
+ * @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
*/
@@ -365,6 +392,7 @@ abstract class AnalysisContext {
* @return the result of resolving the AST structure representing the content of the source in the
* context of the given library
* @throws AnalysisException if the analysis could not be performed
+ * @see #getResolvedCompilationUnit(Source,LibraryElement)
*/
CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement library);
/**
@@ -375,6 +403,7 @@ abstract class AnalysisContext {
* @return the result of resolving the AST structure representing the content of the source in the
* context of the given library
* @throws AnalysisException if the analysis could not be performed
+ * @see #getResolvedCompilationUnit(Source,Source)
*/
CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySource);
/**
@@ -408,6 +437,23 @@ abstract class AnalysisContext {
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.
+ * @return the line information associated with the errors
+ */
+ 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
@@ -417,18 +463,18 @@ class AnalysisException extends JavaException {
* Initialize a newly created exception.
*/
AnalysisException() : super() {
- _jtd_constructor_124_impl();
+ _jtd_constructor_125_impl();
}
- _jtd_constructor_124_impl() {
+ _jtd_constructor_125_impl() {
}
/**
* Initialize a newly created exception to have the given message.
* @param message the message associated with the exception
*/
AnalysisException.con1(String message) : super(message) {
- _jtd_constructor_125_impl(message);
+ _jtd_constructor_126_impl(message);
}
- _jtd_constructor_125_impl(String message) {
+ _jtd_constructor_126_impl(String message) {
}
/**
* Initialize a newly created exception to have the given message and cause.
@@ -436,18 +482,18 @@ class AnalysisException extends JavaException {
* @param cause the underlying exception that caused this exception
*/
AnalysisException.con2(String message, Exception cause) : super(message, cause) {
- _jtd_constructor_126_impl(message, cause);
+ _jtd_constructor_127_impl(message, cause);
}
- _jtd_constructor_126_impl(String message, Exception cause) {
+ _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
*/
AnalysisException.con3(Exception cause) : super.withCause(cause) {
- _jtd_constructor_127_impl(cause);
+ _jtd_constructor_128_impl(cause);
}
- _jtd_constructor_127_impl(Exception cause) {
+ _jtd_constructor_128_impl(Exception cause) {
}
}
/**
@@ -455,7 +501,7 @@ class AnalysisException extends JavaException {
* analysis results associated with a given source.
* @coverage dart.engine
*/
-abstract class ChangeNotice {
+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.
@@ -463,18 +509,6 @@ abstract class ChangeNotice {
*/
CompilationUnit get 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;
- /**
- * 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;
- /**
* Return the source for which the result is being reported.
* @return the source for which the result is being reported
*/
@@ -572,7 +606,7 @@ class ChangeSet {
* context}.
* @coverage dart.engine
*/
-class AnalysisContextImpl implements AnalysisContext {
+class AnalysisContextImpl implements InternalAnalysisContext {
/**
* The source factory used to create the sources that can be analyzed in this context.
*/
@@ -587,10 +621,20 @@ class AnalysisContextImpl implements AnalysisContext {
*/
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";
@@ -599,10 +643,18 @@ class AnalysisContextImpl implements AnalysisContext {
*/
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, SourceInfo info) {
+ _sourceMap[source] = info;
+ }
void applyChanges(ChangeSet changeSet) {
if (changeSet.isEmpty()) {
return;
@@ -646,8 +698,8 @@ class AnalysisContextImpl implements AnalysisContext {
if (htmlUnitInfo == null) {
return null;
}
- HtmlElement element24 = htmlUnitInfo.element;
- if (element24 == null) {
+ HtmlElement element26 = htmlUnitInfo.element;
+ if (element26 == null) {
HtmlUnit unit = htmlUnitInfo.resolvedUnit;
if (unit == null) {
unit = htmlUnitInfo.parsedUnit;
@@ -656,11 +708,11 @@ class AnalysisContextImpl implements AnalysisContext {
}
}
HtmlUnitBuilder builder = new HtmlUnitBuilder(this);
- element24 = builder.buildHtmlElement2(source, unit);
+ element26 = builder.buildHtmlElement2(source, unit);
htmlUnitInfo.resolvedUnit = unit;
- htmlUnitInfo.element = element24;
+ htmlUnitInfo.element = element26;
}
- return element24;
+ return element26;
}
}
SourceKind computeKindOf(Source source) {
@@ -668,8 +720,8 @@ class AnalysisContextImpl implements AnalysisContext {
SourceInfo sourceInfo = getSourceInfo(source);
if (sourceInfo == null) {
return SourceKind.UNKNOWN;
- } else if (sourceInfo is DartInfo) {
- sourceInfo = internalComputeKindOf(source, sourceInfo);
+ } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
+ sourceInfo = internalComputeKindOf(source);
}
return sourceInfo.kind;
}
@@ -683,22 +735,22 @@ class AnalysisContextImpl implements AnalysisContext {
if (libraryInfo == null) {
return null;
}
- LibraryElement element25 = libraryInfo.element;
- if (element25 == null) {
+ LibraryElement element27 = libraryInfo.element;
+ if (element27 == null) {
if (computeKindOf(source) != SourceKind.LIBRARY) {
return null;
}
LibraryResolver resolver = new LibraryResolver.con1(this);
try {
- element25 = resolver.resolveLibrary(source, true);
- if (element25 != null) {
- libraryInfo.element = element25;
+ element27 = resolver.resolveLibrary(source, true);
+ if (element27 != null) {
+ libraryInfo.element = element27;
}
} on AnalysisException catch (exception) {
AnalysisEngine.instance.logger.logError2("Could not resolve the library ${source.fullName}", exception);
}
}
- return element25;
+ return element27;
}
}
LineInfo computeLineInfo(Source source) {
@@ -709,8 +761,8 @@ class AnalysisContextImpl implements AnalysisContext {
}
LineInfo lineInfo4 = sourceInfo.lineInfo;
if (lineInfo4 == null) {
- if (sourceInfo is DartInfo) {
- sourceInfo = internalComputeKindOf(source, sourceInfo);
+ if (identical(sourceInfo, DartInfo.pendingInstance)) {
+ sourceInfo = internalComputeKindOf(source);
}
if (sourceInfo is HtmlUnitInfo) {
parseHtmlUnit(source);
@@ -723,15 +775,33 @@ class AnalysisContextImpl implements AnalysisContext {
return lineInfo4;
}
}
- AnalysisContext extractContext(SourceContainer container) {
- AnalysisContextImpl newContext = AnalysisEngine.instance.createAnalysisContext() as AnalysisContextImpl;
+ CompilationUnit computeResolvableCompilationUnit(Source source) {
+ {
+ CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
+ if (compilationUnitInfo == null) {
+ return null;
+ }
+ CompilationUnit unit = compilationUnitInfo.parsedCompilationUnit;
+ if (unit == null) {
+ unit = compilationUnitInfo.resolvedCompilationUnit;
+ }
+ if (unit != null) {
+ return unit.accept(new ASTCloner()) as CompilationUnit;
+ }
+ unit = internalParseCompilationUnit(compilationUnitInfo, source);
+ compilationUnitInfo.clearParsedUnit();
+ return unit;
+ }
+ }
+ AnalysisContext extractContext(SourceContainer container) => extractContextInto(container, (AnalysisEngine.instance.createAnalysisContext() as AnalysisContextImpl));
+ InternalAnalysisContext extractContextInto(SourceContainer container, InternalAnalysisContext newContext) {
List<Source> sourcesToRemove = new List<Source>();
{
for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
Source source = entry.getKey();
if (container.contains(source)) {
sourcesToRemove.add(source);
- newContext._sourceMap[source] = entry.getValue().copy();
+ newContext.addSourceInfo(source, entry.getValue().copy());
}
}
}
@@ -756,13 +826,14 @@ class AnalysisContextImpl implements AnalysisContext {
}
return element;
}
- List<AnalysisError> getErrors(Source source) {
+ AnalysisErrorInfo getErrors(Source source) {
{
SourceInfo info = getSourceInfo(source);
if (info is CompilationUnitInfo) {
- return ((info as CompilationUnitInfo)).allErrors;
+ CompilationUnitInfo compilationUnitInfo = info as CompilationUnitInfo;
+ return new AnalysisErrorInfoImpl(compilationUnitInfo.allErrors, compilationUnitInfo.lineInfo);
}
- return AnalysisError.NO_ERRORS;
+ return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, info.lineInfo);
}
}
HtmlElement getHtmlElement(Source source) {
@@ -776,22 +847,25 @@ class AnalysisContextImpl implements AnalysisContext {
}
List<Source> getHtmlFilesReferencing(Source source) {
{
- SourceInfo info = getSourceInfo(source);
- if (info is LibraryInfo) {
- return ((info as LibraryInfo)).htmlSources;
- } else if (info is CompilationUnitInfo) {
- List<Source> sources = new List<Source>();
- for (Source librarySource in ((info as CompilationUnitInfo)).librarySources) {
- LibraryInfo libraryInfo = getLibraryInfo(librarySource);
- for (Source htmlSource in libraryInfo.htmlSources) {
- sources.add(htmlSource);
+ List<Source> htmlSources = new List<Source>();
+ while (true) {
+ if (getKindOf(source) == SourceKind.LIBRARY) {
+ } else if (getKindOf(source) == SourceKind.PART) {
+ List<Source> librarySources = getLibrariesContaining(source);
+ for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
+ if (identical(entry.getValue().kind, SourceKind.HTML)) {
+ if (containsAny(((entry.getValue() as HtmlUnitInfo)).librarySources, librarySources)) {
+ htmlSources.add(entry.getKey());
+ }
+ }
}
}
- if (!sources.isEmpty) {
- return new List.from(sources);
- }
+ break;
}
- return Source.EMPTY_ARRAY;
+ if (htmlSources.isEmpty) {
+ return Source.EMPTY_ARRAY;
+ }
+ return new List.from(htmlSources);
}
}
List<Source> get htmlSources => getSources(SourceKind.HTML);
@@ -832,11 +906,18 @@ class AnalysisContextImpl implements AnalysisContext {
}
List<Source> getLibrariesContaining(Source source) {
{
- SourceInfo info = getSourceInfo(source);
- if (info is CompilationUnitInfo) {
- return ((info as CompilationUnitInfo)).librarySources;
+ List<Source> librarySources = new List<Source>();
+ for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
+ if (identical(entry.getValue().kind, SourceKind.LIBRARY)) {
+ if (contains(((entry.getValue() as LibraryInfo)).unitSources, source)) {
+ librarySources.add(entry.getKey());
+ }
+ }
}
- return Source.EMPTY_ARRAY;
+ if (librarySources.isEmpty) {
+ return Source.EMPTY_ARRAY;
+ }
+ return new List.from(librarySources);
}
}
LibraryElement getLibraryElement(Source source) {
@@ -858,16 +939,10 @@ class AnalysisContextImpl implements AnalysisContext {
return null;
}
}
- /**
- * Return a namespace containing mappings for all of the public names defined by the given
- * library.
- * @param library the library whose public namespace is to be returned
- * @return the public namespace of the given library
- */
Namespace getPublicNamespace(LibraryElement library) {
- Source source8 = library.definingCompilationUnit.source;
+ Source source11 = library.definingCompilationUnit.source;
{
- LibraryInfo libraryInfo = getLibraryInfo(source8);
+ LibraryInfo libraryInfo = getLibraryInfo(source11);
if (libraryInfo == null) {
return null;
}
@@ -880,13 +955,6 @@ class AnalysisContextImpl implements AnalysisContext {
return namespace;
}
}
- /**
- * Return a namespace containing mappings for all of the public names defined by the library
- * defined by the given source.
- * @param source the source defining the library whose public namespace is to be returned
- * @return the public namespace corresponding to the library defined by the given source
- * @throws AnalysisException if the public namespace could not be computed
- */
Namespace getPublicNamespace2(Source source) {
{
LibraryInfo libraryInfo = getLibraryInfo(source);
@@ -906,6 +974,22 @@ class AnalysisContextImpl implements AnalysisContext {
return namespace;
}
}
+ CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement library) {
+ if (library == null) {
+ return null;
+ }
+ return getResolvedCompilationUnit2(unitSource, library.source);
+ }
+ CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source librarySource) {
+ {
+ accessed(unitSource);
+ CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSource);
+ if (compilationUnitInfo == null) {
+ return null;
+ }
+ return compilationUnitInfo.resolvedCompilationUnit;
+ }
+ }
SourceFactory get sourceFactory => _sourceFactory;
bool isClientLibrary(Source librarySource) {
SourceInfo sourceInfo = getSourceInfo(librarySource);
@@ -943,6 +1027,7 @@ class AnalysisContextImpl implements AnalysisContext {
}
CompilationUnit parseCompilationUnit(Source source) {
{
+ accessed(source);
CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
if (compilationUnitInfo == null) {
return null;
@@ -951,17 +1036,7 @@ class AnalysisContextImpl implements AnalysisContext {
if (unit == null) {
unit = compilationUnitInfo.parsedCompilationUnit;
if (unit == null) {
- RecordingErrorListener errorListener = new RecordingErrorListener();
- AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorListener);
- Parser parser = new Parser(source, errorListener);
- unit = parser.parseCompilationUnit(scanResult._token);
- LineInfo lineInfo = new LineInfo(scanResult._lineStarts);
- List<AnalysisError> errors = errorListener.getErrors2(source);
- unit.parsingErrors = errors;
- unit.lineInfo = lineInfo;
- compilationUnitInfo.lineInfo = lineInfo;
- compilationUnitInfo.parsedCompilationUnit = unit;
- compilationUnitInfo.parseErrors = errors;
+ unit = internalParseCompilationUnit(compilationUnitInfo, source);
}
}
return unit;
@@ -969,6 +1044,7 @@ class AnalysisContextImpl implements AnalysisContext {
}
HtmlUnit parseHtmlUnit(Source source) {
{
+ accessed(source);
HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(source);
if (htmlUnitInfo == null) {
return null;
@@ -981,17 +1057,7 @@ class AnalysisContextImpl implements AnalysisContext {
unit = result.htmlUnit;
htmlUnitInfo.lineInfo = new LineInfo(result.lineStarts);
htmlUnitInfo.parsedUnit = unit;
- for (SourceInfo sourceInfo in _sourceMap.values) {
- if (sourceInfo is LibraryInfo) {
- ((sourceInfo as LibraryInfo)).removeHtmlSource(source);
- }
- }
- for (Source librarySource in getLibrarySources2(source, unit)) {
- LibraryInfo libraryInfo = getLibraryInfo(librarySource);
- if (libraryInfo != null) {
- libraryInfo.addHtmlSource(source);
- }
- }
+ htmlUnitInfo.librarySources = getLibrarySources2(source, unit);
}
}
return unit;
@@ -1010,51 +1076,28 @@ class AnalysisContextImpl implements AnalysisContext {
return notices;
}
}
- /**
- * Given a table mapping the source for the libraries represented by the corresponding elements to
- * the elements representing the libraries, record those mappings.
- * @param elementMap a table mapping the source for the libraries represented by the elements to
- * the elements representing the libraries
- */
void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
Source htmlSource = _sourceFactory.forUri("dart:html");
{
for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
+ Source librarySource = entry.getKey();
LibraryElement library = entry.getValue();
- LibraryInfo libraryInfo = getLibraryInfo(entry.getKey());
+ LibraryInfo libraryInfo = getLibraryInfo(librarySource);
if (libraryInfo != null) {
libraryInfo.element = library;
libraryInfo.launchable = library.entryPoint != null;
libraryInfo.client = isClient(library, htmlSource, new Set<LibraryElement>());
- }
- Source librarySource = library.source;
- if (librarySource != null) {
- for (SourceInfo info in _sourceMap.values) {
- if (info is CompilationUnitInfo) {
- ((info as CompilationUnitInfo)).removeLibrarySource(librarySource);
- }
- }
- if (libraryInfo != null) {
- libraryInfo.addLibrarySource(librarySource);
- }
+ List<Source> unitSources = new List<Source>();
+ unitSources.add(librarySource);
for (CompilationUnitElement part in library.parts) {
Source partSource = part.source;
- CompilationUnitInfo partInfo = partSource == null ? null : getCompilationUnitInfo(partSource);
- if (partInfo != null) {
- partInfo.addLibrarySource(librarySource);
- }
+ unitSources.add(partSource);
}
+ libraryInfo.unitSources = new List.from(unitSources);
}
}
}
}
- /**
- * 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 errors the resolution errors associated with the source
- * @param lineInfo the line information associated with the source
- */
void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInfo lineInfo5) {
{
CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
@@ -1065,50 +1108,81 @@ class AnalysisContextImpl implements AnalysisContext {
getNotice(source).setErrors(compilationUnitInfo.allErrors, lineInfo5);
}
}
- /**
- * 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 unit the compilation unit associated with the source
- */
void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
{
CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
if (compilationUnitInfo != null) {
compilationUnitInfo.resolvedCompilationUnit = unit;
+ compilationUnitInfo.clearParsedUnit();
getNotice(source).compilationUnit = unit;
}
}
}
- CompilationUnit resolveCompilationUnit(Source source15, LibraryElement library) {
+ CompilationUnit resolveCompilationUnit(Source source20, LibraryElement library) {
if (library == null) {
return null;
}
- return resolveCompilationUnit2(source15, library.source);
+ return resolveCompilationUnit2(source20, library.source);
}
CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySource) {
{
+ accessed(unitSource);
CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(unitSource);
if (compilationUnitInfo == null) {
return null;
}
CompilationUnit unit = compilationUnitInfo.resolvedCompilationUnit;
if (unit == null) {
- computeLibraryElement(librarySource);
- unit = compilationUnitInfo.resolvedCompilationUnit;
+ disableCacheRemoval();
+ try {
+ LibraryElement libraryElement = computeLibraryElement(librarySource);
+ unit = compilationUnitInfo.resolvedCompilationUnit;
+ if (unit == null && libraryElement != null) {
+ Source coreLibrarySource = libraryElement.context.sourceFactory.forUri(DartSdk.DART_CORE);
+ LibraryElement coreElement = computeLibraryElement(coreLibrarySource);
+ TypeProvider typeProvider = new TypeProviderImpl(coreElement);
+ CompilationUnit unitAST = computeResolvableCompilationUnit(unitSource);
+ new DeclarationResolver().resolve(unitAST, find(libraryElement, unitSource));
+ RecordingErrorListener errorListener = new RecordingErrorListener();
+ TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(libraryElement, unitSource, typeProvider, errorListener);
+ unitAST.accept(typeResolverVisitor);
+ 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);
+ unitAST.accept(errorVerifier);
+ ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter);
+ unitAST.accept(constantVerifier);
+ unitAST.resolutionErrors = errorListener.errors;
+ compilationUnitInfo.resolvedCompilationUnit = unitAST;
+ unit = unitAST;
+ }
+ } finally {
+ enableCacheRemoval();
+ }
}
return unit;
}
}
HtmlUnit resolveHtmlUnit(Source unitSource) {
{
+ accessed(unitSource);
HtmlUnitInfo htmlUnitInfo = getHtmlUnitInfo(unitSource);
if (htmlUnitInfo == null) {
return null;
}
HtmlUnit unit = htmlUnitInfo.resolvedUnit;
if (unit == null) {
- computeHtmlElement(unitSource);
- unit = htmlUnitInfo.resolvedUnit;
+ disableCacheRemoval();
+ try {
+ computeHtmlElement(unitSource);
+ unit = htmlUnitInfo.resolvedUnit;
+ if (unit == null) {
+ unit = parseHtmlUnit(unitSource);
+ }
+ } finally {
+ enableCacheRemoval();
+ }
}
return unit;
}
@@ -1159,6 +1233,31 @@ class AnalysisContextImpl implements AnalysisContext {
return librarySources;
}
/**
+ * 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}.
+ * @param source the source that was accessed
+ */
+ void accessed(Source source) {
+ if (_recentlyUsed.contains(source)) {
+ _recentlyUsed.remove(source);
+ _recentlyUsed.add(source);
+ return;
+ }
+ if (_cacheRemovalCount == 0 && _recentlyUsed.length >= _MAX_CACHE_SIZE) {
+ Source removedSource = _recentlyUsed.removeAt(0);
+ SourceInfo sourceInfo = _sourceMap[removedSource];
+ if (sourceInfo is HtmlUnitInfo) {
+ ((sourceInfo as HtmlUnitInfo)).clearParsedUnit();
+ ((sourceInfo as HtmlUnitInfo)).clearResolvedUnit();
+ } else if (sourceInfo is CompilationUnitInfo) {
+ ((sourceInfo as CompilationUnitInfo)).clearParsedUnit();
+ ((sourceInfo as CompilationUnitInfo)).clearResolvedUnit();
+ }
+ }
+ _recentlyUsed.add(source);
+ }
+ /**
* Add all of the sources contained in the given source container to the given list of sources.
* <p>
* Note: This method must only be invoked while we are synchronized on {@link #cacheLock}.
@@ -1173,6 +1272,34 @@ class AnalysisContextImpl implements AnalysisContext {
}
}
/**
+ * Return {@code true} if the given array of sources contains the given source.
+ * @param sources the sources being searched
+ * @param targetSource the source being searched for
+ * @return {@code true} if the given source is in the array
+ */
+ bool contains(List<Source> sources, Source targetSource) {
+ for (Source source in sources) {
+ if (source == targetSource) {
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * Return {@code true} if the given array of sources contains any of the given target sources.
+ * @param sources the sources being searched
+ * @param targetSources the sources being searched for
+ * @return {@code true} if any of the given target sources are in the array
+ */
+ bool containsAny(List<Source> sources, List<Source> targetSources) {
+ for (Source targetSource in targetSources) {
+ if (contains(sources, targetSource)) {
+ return true;
+ }
+ }
+ 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.
* @param source the source for which an information object is being created
@@ -1185,13 +1312,61 @@ class AnalysisContextImpl implements AnalysisContext {
_sourceMap[source] = info;
return info;
} else if (AnalysisEngine.isDartFileName(name)) {
- DartInfo info = DartInfo.instance;
+ DartInfo info = DartInfo.pendingInstance;
_sourceMap[source] = info;
return info;
}
return null;
}
/**
+ * Disable flushing information from the cache until {@link #enableCacheRemoval()} has been
+ * called.
+ */
+ void disableCacheRemoval() {
+ _cacheRemovalCount++;
+ }
+ /**
+ * Re-enable flushing information from the cache.
+ */
+ void enableCacheRemoval() {
+ if (_cacheRemovalCount > 0) {
+ _cacheRemovalCount--;
+ }
+ if (_cacheRemovalCount == 0) {
+ while (_recentlyUsed.length >= _MAX_CACHE_SIZE) {
+ Source removedSource = _recentlyUsed.removeAt(0);
+ SourceInfo sourceInfo = _sourceMap[removedSource];
+ if (sourceInfo is HtmlUnitInfo) {
+ ((sourceInfo as HtmlUnitInfo)).clearParsedUnit();
+ ((sourceInfo as HtmlUnitInfo)).clearResolvedUnit();
+ } else if (sourceInfo is CompilationUnitInfo) {
+ ((sourceInfo as CompilationUnitInfo)).clearParsedUnit();
+ ((sourceInfo as CompilationUnitInfo)).clearResolvedUnit();
+ }
+ }
+ }
+ }
+ /**
+ * 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
+ * such compilation unit.
+ * @param libraryElement the element representing the library being searched through
+ * @param unitSource the source for the compilation unit whose element is to be returned
+ * @return the element representing the compilation unit
+ */
+ CompilationUnitElement find(LibraryElement libraryElement, Source unitSource) {
+ CompilationUnitElement element = libraryElement.definingCompilationUnit;
+ if (element.source == unitSource) {
+ return element;
+ }
+ for (CompilationUnitElement partElement in libraryElement.parts) {
+ if (partElement.source == unitSource) {
+ return partElement;
+ }
+ }
+ 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
* unit information rather than accessing the compilation unit map directly because sources in the
@@ -1210,8 +1385,8 @@ class AnalysisContextImpl implements AnalysisContext {
return sourceInfo as CompilationUnitInfo;
} else if (sourceInfo is CompilationUnitInfo) {
return sourceInfo as CompilationUnitInfo;
- } else if (sourceInfo is DartInfo) {
- sourceInfo = internalComputeKindOf(source, sourceInfo);
+ } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
+ sourceInfo = internalComputeKindOf(source);
if (sourceInfo is CompilationUnitInfo) {
return sourceInfo as CompilationUnitInfo;
}
@@ -1258,8 +1433,8 @@ class AnalysisContextImpl implements AnalysisContext {
return sourceInfo as LibraryInfo;
} else if (sourceInfo is LibraryInfo) {
return sourceInfo as LibraryInfo;
- } else if (sourceInfo is DartInfo) {
- sourceInfo = internalComputeKindOf(source, sourceInfo);
+ } else if (identical(sourceInfo, DartInfo.pendingInstance)) {
+ sourceInfo = internalComputeKindOf(source);
if (sourceInfo is LibraryInfo) {
return sourceInfo as LibraryInfo;
}
@@ -1274,8 +1449,11 @@ class AnalysisContextImpl implements AnalysisContext {
*/
List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) {
List<Source> libraries = new List<Source>();
- htmlUnit.accept(new SimpleXmlVisitor_3(htmlSource, libraries));
- return libraries;
+ htmlUnit.accept(new RecursiveXmlVisitor_6(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.
@@ -1324,20 +1502,33 @@ class AnalysisContextImpl implements AnalysisContext {
return new List.from(sources);
}
/**
- * Return {@code true} if the given compilation unit has a part-of directive.
+ * Return {@code true} if the given compilation unit has a part-of directive but no library
+ * directive.
* @param unit the compilation unit being tested
* @return {@code true} if the compilation unit has a part-of directive
*/
bool hasPartOfDirective(CompilationUnit unit) {
+ bool hasPartOf = false;
for (Directive directive in unit.directives) {
if (directive is PartOfDirective) {
- return true;
+ hasPartOf = true;
+ } else if (directive is LibraryDirective) {
+ return false;
}
}
- return false;
+ return hasPartOf;
}
- SourceInfo internalComputeKindOf(Source source, SourceInfo info) {
+ /**
+ * Compute the kind of the given source. This method should only be invoked when the kind is not
+ * already known. In such a case the source is currently being represented by a {@link DartInfo}.
+ * After this method has run the source will be represented by a new information object that is
+ * appropriate to the computed kind of the source.
+ * @param source the source for which a kind is to be computed
+ * @return the new source info that was created to represent the source
+ */
+ SourceInfo internalComputeKindOf(Source source) {
try {
+ accessed(source);
RecordingErrorListener errorListener = new RecordingErrorListener();
AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorListener);
Parser parser = new Parser(source, errorListener);
@@ -1358,12 +1549,29 @@ class AnalysisContextImpl implements AnalysisContext {
_sourceMap[source] = sourceInfo;
return sourceInfo;
} on AnalysisException catch (exception) {
- return info;
+ DartInfo sourceInfo = DartInfo.errorInstance;
+ _sourceMap[source] = sourceInfo;
+ return sourceInfo;
}
}
+ CompilationUnit internalParseCompilationUnit(CompilationUnitInfo compilationUnitInfo, 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;
+ compilationUnitInfo.lineInfo = lineInfo;
+ compilationUnitInfo.parsedCompilationUnit = unit;
+ compilationUnitInfo.parseErrors = errors;
+ return unit;
+ }
AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListener errorListener) {
AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult();
- Source_ContentReceiver receiver = new Source_ContentReceiver_4(source, errorListener, result);
+ Source_ContentReceiver receiver = new Source_ContentReceiver_7(source, errorListener, result);
try {
source.getContents(receiver);
} catch (exception) {
@@ -1372,6 +1580,27 @@ class AnalysisContextImpl implements AnalysisContext {
return result;
}
/**
+ * 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 libraryInfo the information for the library being invalidated
+ */
+ void invalidateLibraryResolution(Source librarySource, LibraryInfo libraryInfo) {
+ if (libraryInfo != null) {
+ libraryInfo.invalidateElement();
+ libraryInfo.invalidateLaunchable();
+ libraryInfo.invalidatePublicNamespace();
+ libraryInfo.invalidateResolutionErrors();
+ libraryInfo.invalidateResolvedUnit();
+ for (Source unitSource in libraryInfo.unitSources) {
+ CompilationUnitInfo partInfo = getCompilationUnitInfo(unitSource);
+ partInfo.invalidateResolutionErrors();
+ partInfo.invalidateResolvedUnit();
+ }
+ libraryInfo.invalidateUnitSources();
+ }
+ }
+ /**
* Return {@code true} if this library is, or depends on, dart:html.
* @param library the library being tested
* @param visitedLibraries a collection of the libraries that have been visited, used to prevent
@@ -1407,8 +1636,8 @@ class AnalysisContextImpl implements AnalysisContext {
bool performSingleAnalysisTask() {
for (MapEntry<Source, SourceInfo> entry in getMapEntrySet(_sourceMap)) {
SourceInfo sourceInfo = entry.getValue();
- if (identical(sourceInfo, DartInfo.instance) || sourceInfo.kind == null) {
- internalComputeKindOf(entry.getKey(), sourceInfo);
+ if (identical(sourceInfo, DartInfo.pendingInstance)) {
+ internalComputeKindOf(entry.getKey());
return true;
}
}
@@ -1447,7 +1676,18 @@ class AnalysisContextImpl implements AnalysisContext {
computeLibraryElement(entry.getKey());
} on AnalysisException catch (exception) {
libraryInfo.element = null;
- AnalysisEngine.instance.logger.logError2("Could not compute the library element for ${entry.getKey().fullName}", exception);
+ AnalysisEngine.instance.logger.logError2("Could not resolve ${entry.getKey().fullName}", exception);
+ }
+ return true;
+ }
+ } else if (sourceInfo is HtmlUnitInfo) {
+ HtmlUnitInfo unitInfo = sourceInfo as HtmlUnitInfo;
+ if (unitInfo.hasInvalidResolvedUnit()) {
+ try {
+ resolveHtmlUnit(entry.getKey());
+ } on AnalysisException catch (exception) {
+ unitInfo.resolvedUnit = null;
+ AnalysisEngine.instance.logger.logError2("Could not resolve ${entry.getKey().fullName}", exception);
}
return true;
}
@@ -1482,21 +1722,20 @@ class AnalysisContextImpl implements AnalysisContext {
SourceInfo sourceInfo = _sourceMap[source];
if (sourceInfo is HtmlUnitInfo) {
HtmlUnitInfo htmlUnitInfo = sourceInfo as HtmlUnitInfo;
+ htmlUnitInfo.invalidateElement();
htmlUnitInfo.invalidateLineInfo();
htmlUnitInfo.invalidateParsedUnit();
htmlUnitInfo.invalidateResolvedUnit();
+ } else if (sourceInfo is LibraryInfo) {
+ LibraryInfo libraryInfo = sourceInfo as LibraryInfo;
+ invalidateLibraryResolution(source, libraryInfo);
+ _sourceMap[source] = DartInfo.pendingInstance;
} else if (sourceInfo is CompilationUnitInfo) {
- CompilationUnitInfo compilationUnitInfo = sourceInfo as CompilationUnitInfo;
- for (Source librarySource in compilationUnitInfo.librarySources) {
+ for (Source librarySource in getLibrariesContaining(source)) {
LibraryInfo libraryInfo = getLibraryInfo(librarySource);
- if (libraryInfo != null) {
- libraryInfo.invalidateElement();
- libraryInfo.invalidatePublicNamespace();
- libraryInfo.invalidateLaunchable();
- libraryInfo.invalidateClientServer();
- }
+ invalidateLibraryResolution(librarySource, libraryInfo);
}
- _sourceMap[source] = DartInfo.instance;
+ _sourceMap[source] = DartInfo.pendingInstance;
}
}
/**
@@ -1506,14 +1745,9 @@ class AnalysisContextImpl implements AnalysisContext {
void sourceRemoved(Source source) {
CompilationUnitInfo compilationUnitInfo = getCompilationUnitInfo(source);
if (compilationUnitInfo != null) {
- for (Source librarySource in compilationUnitInfo.librarySources) {
+ for (Source librarySource in getLibrariesContaining(source)) {
LibraryInfo libraryInfo = getLibraryInfo(librarySource);
- if (libraryInfo != null) {
- libraryInfo.invalidateElement();
- libraryInfo.invalidatePublicNamespace();
- libraryInfo.invalidateLaunchable();
- libraryInfo.invalidateClientServer();
- }
+ invalidateLibraryResolution(librarySource, libraryInfo);
}
}
_sourceMap.remove(source);
@@ -1524,6 +1758,10 @@ class AnalysisContextImpl implements AnalysisContext {
*/
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;
@@ -1537,44 +1775,89 @@ class AnalysisContextImpl_ScanResult {
AnalysisContextImpl_ScanResult() : super() {
}
}
-class SimpleXmlVisitor_3 extends SimpleXmlVisitor<Object> {
+class RecursiveXmlVisitor_6 extends RecursiveXmlVisitor<Object> {
+ final AnalysisContextImpl AnalysisContextImpl_this;
Source htmlSource;
List<Source> libraries;
- SimpleXmlVisitor_3(this.htmlSource, this.libraries) : super();
+ RecursiveXmlVisitor_6(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) {
if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisContextImpl._ATTRIBUTE_SRC)) {
- Source librarySource = htmlSource.resolve(attribute.value.lexeme);
- if (librarySource.exists()) {
- libraries.add(librarySource);
+ try {
+ Uri uri = new Uri.fromComponents(path: attribute.text);
+ String fileName = uri.path;
+ if (AnalysisEngine.isDartFileName(fileName)) {
+ Source librarySource = AnalysisContextImpl_this._sourceFactory.resolveUri(htmlSource, fileName);
+ if (librarySource.exists()) {
+ libraries.add(librarySource);
+ }
+ }
+ } catch (exception) {
+ AnalysisEngine.instance.logger.logError2("Invalid URL ('${attribute.text}') in script tag in '${htmlSource.fullName}'", exception);
}
}
}
}
- return null;
+ return super.visitXmlTagNode(node);
}
}
-class Source_ContentReceiver_4 implements Source_ContentReceiver {
+class Source_ContentReceiver_7 implements Source_ContentReceiver {
Source source;
AnalysisErrorListener errorListener;
AnalysisContextImpl_ScanResult result;
- Source_ContentReceiver_4(this.source, this.errorListener, this.result);
- accept(CharBuffer contents) {
+ Source_ContentReceiver_7(this.source, this.errorListener, this.result);
+ void accept(CharBuffer contents, int modificationTime4) {
CharBufferScanner scanner = new CharBufferScanner(source, contents, errorListener);
+ result._modificationTime = modificationTime4;
result._token = scanner.tokenize();
result._lineStarts = scanner.lineStarts;
}
- void accept2(String contents) {
+ void accept2(String contents, int modificationTime5) {
StringScanner scanner = new StringScanner(source, contents, errorListener);
+ result._modificationTime = modificationTime5;
result._token = scanner.tokenize();
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
+ * @param lineinfo the line info for the errors
+ */
+ AnalysisErrorInfoImpl(List<AnalysisError> errors, LineInfo lineInfo) {
+ 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.
+ * @return the line information associated with the errors
+ */
+ LineInfo get lineInfo => _lineInfo;
+}
+/**
* The enumeration {@code CacheState} defines the possible states of cached data.
*/
-class CacheState {
+class CacheState implements Comparable<CacheState> {
/**
* A state representing the fact that the data was up-to-date but flushed from the cache in order
* to control memory usage.
@@ -1595,6 +1878,7 @@ class CacheState {
int get ordinal => __ordinal;
CacheState(this.__name, this.__ordinal) {
}
+ int compareTo(CacheState other) => __ordinal - other.__ordinal;
String toString() => __name;
}
/**
@@ -1716,48 +2000,37 @@ class CompilationUnitInfo extends SourceInfo {
*/
List<AnalysisError> _resolutionErrors;
/**
- * The sources for the defining compilation units of the libraries containing the source, or{@code null} if the libraries containing the source are not yet known.
- */
- List<Source> _librarySources = null;
- /**
* Initialize a newly created information holder to be empty.
*/
CompilationUnitInfo() : super() {
}
/**
- * Add the given source to the list of sources for the defining compilation units for the
- * libraries containing this source.
- * @param source the source to be added to the list
- */
- void addLibrarySource(Source source) {
- if (_librarySources == null) {
- _librarySources = new List<Source>();
- }
- _librarySources.add(source);
- }
- /**
* Remove the parsed compilation unit from the cache.
*/
void clearParsedUnit() {
_parsedUnit = null;
+ _parsedUnitState = CacheState.FLUSHED;
}
/**
* Remove the parse errors from the cache.
*/
void clearParseErrors() {
_parseErrors = null;
+ _parseErrorsState = CacheState.FLUSHED;
}
/**
* Remove the resolution errors from the cache.
*/
void clearResolutionErrors() {
_resolutionErrors = null;
+ _resolutionErrorsState = CacheState.FLUSHED;
}
/**
* Remove the resolved compilation unit from the cache.
*/
void clearResolvedUnit() {
_resolvedUnit = null;
+ _resolvedUnitState = CacheState.FLUSHED;
}
CompilationUnitInfo copy() {
CompilationUnitInfo copy = new CompilationUnitInfo();
@@ -1786,16 +2059,6 @@ class CompilationUnitInfo extends SourceInfo {
}
SourceKind get kind => SourceKind.PART;
/**
- * Return the sources for the defining compilation units for the libraries containing this source.
- * @return the sources for the defining compilation units for the libraries containing this source
- */
- List<Source> get librarySources {
- if (_librarySources == null) {
- return Source.EMPTY_ARRAY;
- }
- return new List.from(_librarySources);
- }
- /**
* Return the parsed compilation unit, or {@code null} if the parsed compilation unit is not
* currently cached.
* @return the parsed compilation unit
@@ -1868,19 +2131,6 @@ class CompilationUnitInfo extends SourceInfo {
_resolvedUnit = null;
}
/**
- * Remove the given source from the list of sources for the defining compilation units for the
- * libraries containing this source.
- * @param source the source to be removed to the list
- */
- void removeLibrarySource(Source source) {
- if (_librarySources != null) {
- _librarySources.remove(source);
- if (_librarySources.isEmpty) {
- _librarySources = null;
- }
- }
- }
- /**
* Set the parsed compilation unit to the given compilation unit.
* <p>
* <b>Note:</b> Do not use this method to clear or invalidate the parsed compilation unit. Use
@@ -1927,20 +2177,34 @@ class CompilationUnitInfo extends SourceInfo {
}
}
/**
- * The unique instance of the class {@code DartInfo} acts as a placeholder for Dart compilation
- * units that have not yet had their kind computed.
+ * Instances of the class {@code DartInfo} acts as a placeholder for Dart compilation units that
+ * have not yet had their kind computed.
* @coverage dart.engine
*/
class DartInfo extends SourceInfo {
/**
- * The unique instance of this class.
+ * The instance of this class used to represent a compilation unit for which an attempt was made
+ * to compute the kind but the kind could not be computed.
*/
- static DartInfo _UniqueInstance = new DartInfo();
+ static DartInfo _ErrorInstance = new DartInfo();
/**
- * Return the unique instance of this class.
- * @return the unique instance of this class
+ * The instance of this class used to represent a compilation unit for which no attempt has been
+ * made to compute the kind.
*/
- static DartInfo get instance => _UniqueInstance;
+ static DartInfo _PendingInstance = new DartInfo();
+ /**
+ * Return an instance of this class representing a compilation unit for which an attempt was made
+ * to compute the kind but the kind could not be computed.
+ * @return an instance of this class used to indicate that the computation of the kind resulted in
+ * an error and there is no point trying again
+ */
+ static DartInfo get errorInstance => _ErrorInstance;
+ /**
+ * Return an instance of this class representing a compilation unit for which no attempt has been
+ * made to compute the kind.
+ * @return an instance of this class used to indicate that the computation of the kind is pending
+ */
+ static DartInfo get pendingInstance => _PendingInstance;
/**
* Prevent the creation of instances of this class.
*/
@@ -1950,24 +2214,261 @@ class DartInfo extends SourceInfo {
SourceKind get kind => SourceKind.UNKNOWN;
}
/**
- * Instances of the class {@code HtmlUnitInfo} maintain the information cached by an analysis
- * context about an individual HTML file.
+ * 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 HtmlUnitInfo extends SourceInfo {
- /**
- * The state of the cached parsed (but not resolved) HTML unit.
- */
- CacheState _parsedUnitState = CacheState.INVALID;
+class DelegatingAnalysisContextImpl extends AnalysisContextImpl {
/**
- * The parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached.
+ * 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
+ * #setSourceFactory(SourceFactory) is called, and references the analysis context in the{@link DartUriResolver} in the {@link SourceFactory}, this analysis context assumes that there
+ * will be such a resolver.
*/
- HtmlUnit _parsedUnit;
+ InternalAnalysisContext _sdkAnalysisContext;
/**
- * The state of the cached parsed and resolved HTML unit.
+ * Initialize a newly created delegating analysis context.
*/
- CacheState _resolvedUnitState = CacheState.INVALID;
- /**
+ DelegatingAnalysisContextImpl() : super() {
+ }
+ void addSourceInfo(Source source, SourceInfo info) {
+ if (source.isInSystemLibrary()) {
+ _sdkAnalysisContext.addSourceInfo(source, info);
+ } else {
+ super.addSourceInfo(source, info);
+ }
+ }
+ List<AnalysisError> computeErrors(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeErrors(source);
+ } else {
+ return super.computeErrors(source);
+ }
+ }
+ HtmlElement computeHtmlElement(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeHtmlElement(source);
+ } else {
+ return super.computeHtmlElement(source);
+ }
+ }
+ SourceKind computeKindOf(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeKindOf(source);
+ } else {
+ return super.computeKindOf(source);
+ }
+ }
+ LibraryElement computeLibraryElement(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeLibraryElement(source);
+ } else {
+ return super.computeLibraryElement(source);
+ }
+ }
+ LineInfo computeLineInfo(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeLineInfo(source);
+ } else {
+ return super.computeLineInfo(source);
+ }
+ }
+ CompilationUnit computeResolvableCompilationUnit(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.computeResolvableCompilationUnit(source);
+ } else {
+ return super.computeResolvableCompilationUnit(source);
+ }
+ }
+ AnalysisErrorInfo getErrors(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getErrors(source);
+ } else {
+ return super.getErrors(source);
+ }
+ }
+ HtmlElement getHtmlElement(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getHtmlElement(source);
+ } else {
+ return super.getHtmlElement(source);
+ }
+ }
+ List<Source> getHtmlFilesReferencing(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getHtmlFilesReferencing(source);
+ } else {
+ return super.getHtmlFilesReferencing(source);
+ }
+ }
+ SourceKind getKindOf(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getKindOf(source);
+ } else {
+ return super.getKindOf(source);
+ }
+ }
+ List<Source> getLibrariesContaining(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getLibrariesContaining(source);
+ } else {
+ return super.getLibrariesContaining(source);
+ }
+ }
+ LibraryElement getLibraryElement(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getLibraryElement(source);
+ } else {
+ return super.getLibraryElement(source);
+ }
+ }
+ List<Source> get librarySources => ArrayUtils.addAll(super.librarySources, _sdkAnalysisContext.librarySources);
+ LineInfo getLineInfo(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getLineInfo(source);
+ } else {
+ return super.getLineInfo(source);
+ }
+ }
+ Namespace getPublicNamespace(LibraryElement library) {
+ Source source12 = library.source;
+ if (source12.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getPublicNamespace(library);
+ } else {
+ return super.getPublicNamespace(library);
+ }
+ }
+ Namespace getPublicNamespace2(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getPublicNamespace2(source);
+ } else {
+ return super.getPublicNamespace2(source);
+ }
+ }
+ CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement library) {
+ if (unitSource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getResolvedCompilationUnit(unitSource, library);
+ } else {
+ return super.getResolvedCompilationUnit(unitSource, library);
+ }
+ }
+ CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source librarySource) {
+ if (unitSource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.getResolvedCompilationUnit2(unitSource, librarySource);
+ } else {
+ return super.getResolvedCompilationUnit2(unitSource, librarySource);
+ }
+ }
+ bool isClientLibrary(Source librarySource) {
+ if (librarySource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.isClientLibrary(librarySource);
+ } else {
+ return super.isClientLibrary(librarySource);
+ }
+ }
+ bool isServerLibrary(Source librarySource) {
+ if (librarySource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.isServerLibrary(librarySource);
+ } else {
+ return super.isServerLibrary(librarySource);
+ }
+ }
+ CompilationUnit parseCompilationUnit(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.parseCompilationUnit(source);
+ } else {
+ return super.parseCompilationUnit(source);
+ }
+ }
+ HtmlUnit parseHtmlUnit(Source source) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.parseHtmlUnit(source);
+ } else {
+ return super.parseHtmlUnit(source);
+ }
+ }
+ void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
+ if (elementMap.isEmpty) {
+ return;
+ }
+ Source source = new JavaIterator(elementMap.keys.toSet()).next();
+ if (source.isInSystemLibrary()) {
+ _sdkAnalysisContext.recordLibraryElements(elementMap);
+ } else {
+ super.recordLibraryElements(elementMap);
+ }
+ }
+ void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInfo lineInfo) {
+ if (source.isInSystemLibrary()) {
+ _sdkAnalysisContext.recordResolutionErrors(source, errors, lineInfo);
+ } else {
+ super.recordResolutionErrors(source, errors, lineInfo);
+ }
+ }
+ void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
+ if (source.isInSystemLibrary()) {
+ _sdkAnalysisContext.recordResolvedCompilationUnit(source, unit);
+ } else {
+ super.recordResolvedCompilationUnit(source, unit);
+ }
+ }
+ CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
+ if (source.isInSystemLibrary()) {
+ return _sdkAnalysisContext.resolveCompilationUnit(source, library);
+ } else {
+ return super.resolveCompilationUnit(source, library);
+ }
+ }
+ CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySource) {
+ if (unitSource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySource);
+ } else {
+ return super.resolveCompilationUnit2(unitSource, librarySource);
+ }
+ }
+ HtmlUnit resolveHtmlUnit(Source unitSource) {
+ if (unitSource.isInSystemLibrary()) {
+ return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
+ } else {
+ return super.resolveHtmlUnit(unitSource);
+ }
+ }
+ void setContents(Source source, String contents) {
+ if (source.isInSystemLibrary()) {
+ _sdkAnalysisContext.setContents(source, contents);
+ } else {
+ super.setContents(source, contents);
+ }
+ }
+ void set sourceFactory(SourceFactory factory) {
+ super.sourceFactory = factory;
+ DartSdk sdk = factory.dartSdk;
+ if (sdk != null) {
+ _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
+ } else {
+ throw new IllegalStateException("SourceFactorys provided to DelegatingAnalysisContextImpls must have a DartSdk associated with the provided SourceFactory.");
+ }
+ }
+}
+/**
+ * Instances of the class {@code HtmlUnitInfo} maintain the information cached by an analysis
+ * context about an individual HTML file.
+ * @coverage dart.engine
+ */
+class HtmlUnitInfo extends SourceInfo {
+ /**
+ * 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 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;
@@ -1980,6 +2481,14 @@ class HtmlUnitInfo extends SourceInfo {
*/
HtmlElement _element;
/**
+ * The state of the cached library sources.
+ */
+ CacheState _librarySourcesState = CacheState.INVALID;
+ /**
+ * The sources of libraries referenced by this HTML file.
+ */
+ List<Source> _librarySources = Source.EMPTY_ARRAY;
+ /**
* Initialize a newly created information holder to be empty.
*/
HtmlUnitInfo() : super() {
@@ -1989,12 +2498,14 @@ class HtmlUnitInfo extends SourceInfo {
*/
void clearParsedUnit() {
_parsedUnit = null;
+ _parsedUnitState = CacheState.FLUSHED;
}
/**
* Remove the resolved HTML unit from the cache.
*/
void clearResolvedUnit() {
_resolvedUnit = null;
+ _resolvedUnitState = CacheState.FLUSHED;
}
HtmlUnitInfo copy() {
HtmlUnitInfo copy = new HtmlUnitInfo();
@@ -2009,6 +2520,11 @@ class HtmlUnitInfo extends SourceInfo {
HtmlElement get element => _element;
SourceKind get kind => SourceKind.HTML;
/**
+ * Return the sources of libraries referenced by this HTML file.
+ * @return the sources of libraries referenced by this HTML file
+ */
+ List<Source> get librarySources => _librarySources;
+ /**
* Return the parsed HTML unit, or {@code null} if the parsed HTML unit is not currently cached.
* @return the parsed HTML unit
*/
@@ -2042,6 +2558,13 @@ class HtmlUnitInfo extends SourceInfo {
_element = null;
}
/**
+ * Mark the library sources as needing to be recomputed.
+ */
+ void invalidateLibrarySources() {
+ _librarySourcesState = CacheState.INVALID;
+ _librarySources = Source.EMPTY_ARRAY;
+ }
+ /**
* Mark the parsed HTML unit as needing to be recomputed.
*/
void invalidateParsedUnit() {
@@ -2052,6 +2575,7 @@ class HtmlUnitInfo extends SourceInfo {
* Mark the resolved HTML unit as needing to be recomputed.
*/
void invalidateResolvedUnit() {
+ invalidateElement();
_resolvedUnitState = CacheState.INVALID;
_resolvedUnit = null;
}
@@ -2066,6 +2590,14 @@ class HtmlUnitInfo extends SourceInfo {
_elementState = CacheState.VALID;
}
/**
+ * Set the sources of libraries referenced by this HTML file to the given sources.
+ * @param sources the sources of libraries referenced by this HTML file
+ */
+ void set librarySources(List<Source> sources) {
+ _librarySources = sources;
+ _librarySourcesState = CacheState.VALID;
+ }
+ /**
* Set the parsed HTML unit to the given HTML unit.
* <p>
* <b>Note:</b> Do not use this method to clear or invalidate the HTML unit. Use either{@link #clearParsedUnit()} or {@link #invalidateParsedUnit()}.
@@ -2090,6 +2622,504 @@ class HtmlUnitInfo extends SourceInfo {
}
}
/**
+ * 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
+ * @param exception the exception being reported
+ */
+ 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_175_impl();
+ }
+ _jtd_constructor_175_impl() {
+ _jtd_constructor_176_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_176_impl(context);
+ }
+ _jtd_constructor_176_impl(InternalAnalysisContext context) {
+ _basis = context;
+ }
+ void addSourceInfo(Source source, SourceInfo info) {
+ _basis.addSourceInfo(source, info);
+ }
+ void applyChanges(ChangeSet changeSet) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-applyChanges");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ _basis.applyChanges(changeSet);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<AnalysisError> computeErrors(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-computeErrors");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<AnalysisError> errors = _basis.computeErrors(source);
+ instrumentation.metric2("Errors-count", errors.length);
+ return errors;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ HtmlElement computeHtmlElement(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-computeHtmlElement");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.computeHtmlElement(source);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ SourceKind computeKindOf(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-computeKindOf");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.computeKindOf(source);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ LibraryElement computeLibraryElement(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-computeLibraryElement");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.computeLibraryElement(source);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ LineInfo computeLineInfo(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-computeLineInfo");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.computeLineInfo(source);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ CompilationUnit computeResolvableCompilationUnit(Source source) => _basis.computeResolvableCompilationUnit(source);
+ AnalysisContext extractContext(SourceContainer container) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-extractContext");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ InstrumentedAnalysisContextImpl newContext = new InstrumentedAnalysisContextImpl();
+ _basis.extractContextInto(container, newContext._basis);
+ return newContext;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ InternalAnalysisContext extractContextInto(SourceContainer container, InternalAnalysisContext newContext) => _basis.extractContextInto(container, newContext);
+ /**
+ * @return the underlying {@link AnalysisContext}.
+ */
+ AnalysisContext get basis => _basis;
+ Element getElement(ElementLocation location) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getElement");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getElement(location);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ AnalysisErrorInfo getErrors(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getErrors");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ AnalysisErrorInfo ret = _basis.getErrors(source);
+ if (ret != null) {
+ instrumentation.metric2("Errors-count", ret.errors.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ HtmlElement getHtmlElement(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getHtmlElement");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getHtmlElement(source);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> getHtmlFilesReferencing(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getHtmlFilesReferencing");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.getHtmlFilesReferencing(source);
+ if (ret != null) {
+ instrumentation.metric2("Source-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> get htmlSources {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getHtmlSources");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.htmlSources;
+ if (ret != null) {
+ instrumentation.metric2("Source-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ SourceKind getKindOf(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getKindOf");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getKindOf(source);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> get launchableClientLibrarySources {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLaunchableClientLibrarySources");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.launchableClientLibrarySources;
+ if (ret != null) {
+ instrumentation.metric2("Source-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> get launchableServerLibrarySources {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLaunchableServerLibrarySources");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.launchableServerLibrarySources;
+ if (ret != null) {
+ instrumentation.metric2("Source-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> getLibrariesContaining(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLibrariesContaining");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.getLibrariesContaining(source);
+ 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 {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getLibraryElement(source);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<Source> get librarySources {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLibrarySources");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<Source> ret = _basis.librarySources;
+ if (ret != null) {
+ instrumentation.metric2("Source-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ LineInfo getLineInfo(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getLineInfo");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getLineInfo(source);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ Namespace getPublicNamespace(LibraryElement library) => _basis.getPublicNamespace(library);
+ Namespace getPublicNamespace2(Source source) => _basis.getPublicNamespace2(source);
+ CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement library) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getResolvedCompilationUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getResolvedCompilationUnit(unitSource, library);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source librarySource) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getResolvedCompilationUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.getResolvedCompilationUnit2(unitSource, librarySource);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ SourceFactory get sourceFactory {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-getSourceFactory");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.sourceFactory;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ bool isClientLibrary(Source librarySource) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-isClientLibrary");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.isClientLibrary(librarySource);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ bool isServerLibrary(Source librarySource) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-isServerLibrary");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.isServerLibrary(librarySource);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ void mergeContext(AnalysisContext context) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-mergeContext");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ if (context is InstrumentedAnalysisContextImpl) {
+ context = ((context as InstrumentedAnalysisContextImpl))._basis;
+ }
+ _basis.mergeContext(context);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ CompilationUnit parseCompilationUnit(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-parseCompilationUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.parseCompilationUnit(source);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ HtmlUnit parseHtmlUnit(Source source) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-parseHtmlUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.parseHtmlUnit(source);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ List<ChangeNotice> performAnalysisTask() {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-performAnalysisTask");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ List<ChangeNotice> ret = _basis.performAnalysisTask();
+ if (ret != null) {
+ instrumentation.metric2("ChangeNotice-count", ret.length);
+ }
+ return ret;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
+ _basis.recordLibraryElements(elementMap);
+ }
+ void recordResolutionErrors(Source source, List<AnalysisError> errors, LineInfo lineInfo) {
+ _basis.recordResolutionErrors(source, errors, lineInfo);
+ }
+ void recordResolvedCompilationUnit(Source source, CompilationUnit unit) {
+ _basis.recordResolvedCompilationUnit(source, unit);
+ }
+ CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement library) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-resolveCompilationUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.resolveCompilationUnit(unitSource, library);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySource) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-resolveCompilationUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.resolveCompilationUnit2(unitSource, librarySource);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ HtmlUnit resolveHtmlUnit(Source htmlSource) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-resolveHtmlUnit");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.resolveHtmlUnit(htmlSource);
+ } on AnalysisException catch (e) {
+ recordAnalysisException(instrumentation, e);
+ throw e;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ void setContents(Source source, String contents) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-setContents");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ _basis.setContents(source, contents);
+ } finally {
+ instrumentation.log();
+ }
+ }
+ void set sourceFactory(SourceFactory factory) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-setSourceFactory");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ _basis.sourceFactory = factory;
+ } finally {
+ instrumentation.log();
+ }
+ }
+ Iterable<Source> sourcesToResolve(List<Source> changedSources) {
+ InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis-sourcesToResolve");
+ try {
+ instrumentation.metric3("contextId", _contextId);
+ return _basis.sourcesToResolve(changedSources);
+ } finally {
+ instrumentation.log();
+ }
+ }
+}
+/**
+ * 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, SourceInfo 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
+ * library.
+ * @param source the compilation unit for which an AST structure should be returned
+ * @return the AST structure representing the content of the source
+ * @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.
+ * @param container the container containing sources that should be removed from this context and
+ * added to the returned context
+ * @param newContext the context to be initialized
+ * @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.
+ * @param library the library whose public namespace is to be returned
+ * @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.
+ * @param source the source defining the library whose public namespace is to be returned
+ * @return the public namespace corresponding to the library defined by the given source
+ * @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.
+ * @param elementMap a table mapping the source for the libraries represented by the elements to
+ * 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 errors the resolution errors associated with the source
+ * @param lineInfo the line information associated with the source
+ */
+ void recordResolutionErrors(Source source, 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 unit the compilation unit associated with the source
+ */
+ void recordResolvedCompilationUnit(Source source, CompilationUnit unit);
+}
+/**
* Instances of the class {@code LibraryInfo} maintain the information cached by an analysis context
* about an individual library.
* @coverage dart.engine
@@ -2113,6 +3143,15 @@ class LibraryInfo extends CompilationUnitInfo {
*/
LibraryElement _element;
/**
+ * The state of the cached unit sources.
+ */
+ CacheState _unitSourcesState = CacheState.INVALID;
+ /**
+ * The sources of the compilation units that compose the library, including both the defining
+ * compilation unit and any parts.
+ */
+ List<Source> _unitSources = Source.EMPTY_ARRAY;
+ /**
* The state of the cached public namespace.
*/
CacheState _publicNamespaceState = CacheState.INVALID;
@@ -2133,35 +3172,23 @@ class LibraryInfo extends CompilationUnitInfo {
*/
int _bitmask = 0;
/**
- * The sources for the HTML files that reference this library (via a script tag), or {@code null}if there are no HTML files that reference the library or if the HTML files are not yet known.
- */
- List<Source> _htmlSources = null;
- /**
* Initialize a newly created information holder to be empty.
*/
LibraryInfo() : super() {
}
/**
- * Add the given source to the list of sources for the HTML files that reference this library.
- * @param source the source to be added to the list
- */
- void addHtmlSource(Source source) {
- if (_htmlSources == null) {
- _htmlSources = new List<Source>();
- }
- _htmlSources.add(source);
- }
- /**
* Remove the library element from the cache.
*/
void clearElement() {
_element = null;
+ _elementState = CacheState.FLUSHED;
}
/**
* Remove the public namespace from the cache.
*/
void clearPublicNamespace() {
_publicNamespace = null;
+ _publicNamespaceState = CacheState.FLUSHED;
}
LibraryInfo copy() {
LibraryInfo copy = new LibraryInfo();
@@ -2174,16 +3201,6 @@ class LibraryInfo extends CompilationUnitInfo {
* @return the element representing the library
*/
LibraryElement get element => _element;
- /**
- * Return the sources for the HTML files that reference this library.
- * @return the sources for the HTML files that reference this library
- */
- List<Source> get htmlSources {
- if (_htmlSources == null) {
- return Source.EMPTY_ARRAY;
- }
- return new List.from(_htmlSources);
- }
SourceKind get kind => SourceKind.LIBRARY;
/**
* Return the public namespace of the library, or {@code null} if the namespace is not currently
@@ -2192,6 +3209,12 @@ class LibraryInfo extends CompilationUnitInfo {
*/
Namespace get publicNamespace => _publicNamespace;
/**
+ * Return the sources of the compilation units that compose the library, including both the
+ * defining compilation unit and any parts.
+ * @return the sources of the compilation units that compose the library
+ */
+ List<Source> get unitSources => _unitSources;
+ /**
* Return {@code true} if the client/ server flag needs to be recomputed.
* @return {@code true} if the client/ server flag needs to be recomputed
*/
@@ -2240,38 +3263,32 @@ class LibraryInfo extends CompilationUnitInfo {
_publicNamespace = null;
}
/**
- * Return <code>true</code> if this library is client based code: the library depends on the html
+ * Mark the compilation unit sources as needing to be recomputed.
+ */
+ void invalidateUnitSources() {
+ _unitSourcesState = CacheState.INVALID;
+ _unitSources = Source.EMPTY_ARRAY;
+ }
+ /**
+ * Return {@code true} if this library is client based code: the library depends on the html
* library.
- * @return <code>true</code> if this library is client based code: the library depends on the html
+ * @return {@code true} if this library is client based code: the library depends on the html
* library
*/
bool isClient() => (_bitmask & _CLIENT_CODE) != 0;
/**
- * Return <code>true</code> if this library is launchable: the file includes a main method.
- * @return <code>true</code> if this library is launchable: the file includes a main method
+ * Return {@code true} if this library is launchable: the file includes a main method.
+ * @return {@code true} if this library is launchable: the file includes a main method
*/
bool isLaunchable() => (_bitmask & _LAUNCHABLE) != 0;
/**
- * Return <code>true</code> if this library is server based code: the library does not depends on
- * the html library.
- * @return <code>true</code> if this library is server based code: the library does not depends on
- * the html library
+ * Return {@code true} if this library is server based code: the library does not depends on the
+ * html library.
+ * @return {@code true} if this library is server based code: the library does not depends on the
+ * html library
*/
bool isServer() => (_bitmask & _CLIENT_CODE) == 0;
/**
- * Remove the given source from the list of sources for the HTML files that reference this
- * library.
- * @param source the source to be removed to the list
- */
- void removeHtmlSource(Source source) {
- if (_htmlSources != null) {
- _htmlSources.remove(source);
- if (_htmlSources.isEmpty) {
- _htmlSources = null;
- }
- }
- }
- /**
* Sets the value of the client/ server flag.
* <p>
* <b>Note:</b> Do not use this method to invalidate the flag, use{@link #invalidateClientServer()}.
@@ -2319,6 +3336,14 @@ class LibraryInfo extends CompilationUnitInfo {
_publicNamespace = namespace;
_publicNamespaceState = CacheState.VALID;
}
+ /**
+ * Set the sources of the compilation units that compose the library to the given sources.
+ * @param sources the sources of the compilation units that compose the library
+ */
+ void set unitSources(List<Source> sources) {
+ _unitSourcesState = CacheState.VALID;
+ _unitSources = sources;
+ }
void copyFrom(SourceInfo info) {
super.copyFrom(info);
}
@@ -2364,16 +3389,87 @@ class RecordingErrorListener implements AnalysisErrorListener {
}
}
void onError(AnalysisError event) {
- Source source9 = event.source;
- List<AnalysisError> errorsForSource = _errors[source9];
- if (_errors[source9] == null) {
+ Source source13 = event.source;
+ List<AnalysisError> errorsForSource = _errors[source13];
+ if (_errors[source13] == null) {
errorsForSource = new List<AnalysisError>();
- _errors[source9] = errorsForSource;
+ _errors[source13] = errorsForSource;
}
errorsForSource.add(event);
}
}
/**
+ * Instances of the class {@code ResolutionEraser} remove any resolution information from an AST
+ * structure when used to visit that structure.
+ */
+class ResolutionEraser extends GeneralizingASTVisitor<Object> {
+ Object visitAssignmentExpression(AssignmentExpression node) {
+ node.element = null;
+ return super.visitAssignmentExpression(node);
+ }
+ Object visitBinaryExpression(BinaryExpression node) {
+ node.element = null;
+ return super.visitBinaryExpression(node);
+ }
+ Object visitCompilationUnit(CompilationUnit node) {
+ node.element = null;
+ return super.visitCompilationUnit(node);
+ }
+ Object visitConstructorDeclaration(ConstructorDeclaration node) {
+ node.element = null;
+ return super.visitConstructorDeclaration(node);
+ }
+ Object visitConstructorName(ConstructorName node) {
+ node.element = null;
+ return super.visitConstructorName(node);
+ }
+ Object visitDirective(Directive node) {
+ node.element = null;
+ return super.visitDirective(node);
+ }
+ Object visitExpression(Expression node) {
+ node.staticType = null;
+ node.propagatedType = null;
+ return super.visitExpression(node);
+ }
+ Object visitFunctionExpression(FunctionExpression node) {
+ node.element = null;
+ return super.visitFunctionExpression(node);
+ }
+ Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
+ node.element = null;
+ return super.visitFunctionExpressionInvocation(node);
+ }
+ Object visitIndexExpression(IndexExpression node) {
+ node.element = null;
+ return super.visitIndexExpression(node);
+ }
+ Object visitInstanceCreationExpression(InstanceCreationExpression node) {
+ node.element = null;
+ return super.visitInstanceCreationExpression(node);
+ }
+ Object visitPostfixExpression(PostfixExpression node) {
+ node.element = null;
+ return super.visitPostfixExpression(node);
+ }
+ Object visitPrefixExpression(PrefixExpression node) {
+ node.element = null;
+ return super.visitPrefixExpression(node);
+ }
+ Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
+ node.element = null;
+ return super.visitRedirectingConstructorInvocation(node);
+ }
+ Object visitSimpleIdentifier(SimpleIdentifier node) {
+ node.element = null;
+ return super.visitSimpleIdentifier(node);
+ }
+ Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
+ node.element = null;
+ return super.visitSuperConstructorInvocation(node);
+ }
+}
+/**
* Instances of the class {@code SourceInfo} maintain the information cached by an analysis context
* about an individual source.
* @coverage dart.engine
@@ -2398,6 +3494,7 @@ abstract class SourceInfo {
*/
void clearLineInfo() {
_lineInfo = null;
+ _lineInfoState = CacheState.FLUSHED;
}
/**
* Return a copy of this information holder.
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/element.dart ('k') | pkg/analyzer_experimental/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698