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

Unified Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1182303006: Re-enable and add new HTML support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Move a private constant Created 5 years, 6 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/lib/src/context/context.dart
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index 52ab424cb7f83e9e331cdc5b2a166229551f11ce..6b1a8a4d9a0e5f5e011e0efd894309973ff1aca0 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -36,7 +36,9 @@ import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/manager.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/general.dart';
+import 'package:analyzer/task/html.dart';
import 'package:analyzer/task/model.dart';
+import 'package:html/dom.dart' show Document;
/**
* Type of callback functions used by PendingFuture. Functions of this type
@@ -560,16 +562,27 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
@override
- List<AnalysisError> computeErrors(Source source) =>
- _computeResult(source, DART_ERRORS);
+ List<AnalysisError> computeErrors(Source source) {
+ String name = source.shortName;
+ if (AnalysisEngine.isDartFileName(name)) {
+ return _computeResult(source, DART_ERRORS);
+ } else if (AnalysisEngine.isHtmlFileName(name)) {
+ return _computeResult(source, HTML_ERRORS);
+ }
+ return AnalysisError.NO_ERRORS;
+ }
@override
List<Source> computeExportedLibraries(Source source) =>
_computeResult(source, EXPORTED_LIBRARIES);
@override
- // TODO(brianwilkerson) Implement this.
- HtmlElement computeHtmlElement(Source source) => null;
+ HtmlElement computeHtmlElement(Source source) {
+ // TODO(brianwilkerson) Implement this. For the time being, we compute the
+ // data that will implicitly be computed by creating an element.
+ _computeResult(source, REFERENCED_LIBRARIES);
+ return null;
+ }
@override
List<Source> computeImportedLibraries(Source source) =>
@@ -758,7 +771,15 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
AnalysisErrorInfo getErrors(Source source) {
- return dartWorkManager.getErrors(source);
+ String name = source.shortName;
+ if (AnalysisEngine.isDartFileName(name)) {
+ return dartWorkManager.getErrors(source);
+ } else if (AnalysisEngine.isHtmlFileName(name)) {
+ List<AnalysisError> errors = analysisCache.getValue(source, HTML_ERRORS);
+ // TODO(brianwilkerson) We don't currently have line info for HTML files.
+ return new AnalysisErrorInfoImpl(errors, null);
+ }
+ return new AnalysisErrorInfoImpl(null, null);
Paul Berry 2015/06/15 21:34:38 The old task model does this instead: return new
Brian Wilkerson 2015/06/16 16:28:08 Done
}
@override
@@ -773,39 +794,20 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
List<Source> getHtmlFilesReferencing(Source source) {
Paul Berry 2015/06/15 21:34:38 What's the contract on this function? Is it suppo
Brian Wilkerson 2015/06/16 16:28:08 Yes.
- // TODO(brianwilkerson) Implement this.
- SourceKind sourceKind = getKindOf(source);
- if (sourceKind == null) {
+ if (!AnalysisEngine.isDartFileName(source.shortName)) {
return Source.EMPTY_LIST;
}
List<Source> htmlSources = <Source>[];
-// while (true) {
-// if (sourceKind == SourceKind.PART) {
-// List<Source> librarySources = getLibrariesContaining(source);
-// for (Source source in _cache.sources) {
-// CacheEntry entry = _cache.get(source);
-// if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
-// List<Source> referencedLibraries =
-// (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
-// if (_containsAny(referencedLibraries, librarySources)) {
-// htmlSources.add(source);
-// }
-// }
-// }
-// } else {
-// for (Source source in _cache.sources) {
-// CacheEntry entry = _cache.get(source);
-// if (entry.getValue(SOURCE_KIND) == SourceKind.HTML) {
-// List<Source> referencedLibraries =
-// (entry as HtmlEntry).getValue(HtmlEntry.REFERENCED_LIBRARIES);
-// if (_contains(referencedLibraries, source)) {
-// htmlSources.add(source);
-// }
-// }
-// }
-// }
-// break;
-// }
+ List<Source> librarySources = getLibrariesContaining(source);
+ for (Source source in _cache.sources) {
+ if (AnalysisEngine.isHtmlFileName(source.shortName)) {
+ List<Source> referencedLibraries =
+ analysisCache.getValue(source, REFERENCED_LIBRARIES);
+ if (_containsAny(referencedLibraries, librarySources)) {
+ htmlSources.add(source);
+ }
+ }
+ }
if (htmlSources.isEmpty) {
return Source.EMPTY_LIST;
Paul Berry 2015/06/15 21:34:38 Nit: it seems like the benefit this confers is tin
Brian Wilkerson 2015/06/16 16:28:08 The places where we've seen benefit are where the
}
@@ -854,12 +856,10 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
List<Source> getLibrariesReferencedFromHtml(Source htmlSource) {
Paul Berry 2015/06/15 21:34:38 Similar concern about the contract on this functio
Brian Wilkerson 2015/06/16 16:28:08 In general, the "get" methods are lazy, returning
- // TODO(brianwilkerson) Implement this.
-// cache.CacheEntry entry = getReadableSourceEntryOrNull(htmlSource);
-// if (entry is HtmlEntry) {
-// HtmlEntry htmlEntry = entry;
-// return htmlEntry.getValue(HtmlEntry.REFERENCED_LIBRARIES);
-// }
+ CacheEntry entry = _cache.get(htmlSource);
+ if (entry != null) {
+ return entry.getValue(REFERENCED_LIBRARIES);
+ }
return Source.EMPTY_LIST;
}
@@ -1030,12 +1030,17 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
@override
- ht.HtmlUnit parseHtmlUnit(Source source) {
+ Document parseDocument(Source source) {
Paul Berry 2015/06/15 21:34:38 How about calling this "parseHtmlDocument" instead
Brian Wilkerson 2015/06/16 16:28:08 Done
if (!AnalysisEngine.isHtmlFileName(source.shortName)) {
return null;
}
- // TODO(brianwilkerson) Implement HTML analysis.
- return null; //_computeResult(source, null);
+ return _computeResult(source, DOCUMENT);
+ }
+
+ @override
+ @deprecated // use parseDocument(source)
+ ht.HtmlUnit parseHtmlUnit(Source source) {
+ return null;
Paul Berry 2015/06/15 21:34:38 Instead of returning null, I'd suggest doing "thro
Brian Wilkerson 2015/06/16 16:28:08 Done
}
@override
@@ -1058,20 +1063,6 @@ class AnalysisContextImpl implements InternalAnalysisContext {
});
}
- void _evaluatePendingFutures() {
- for (AnalysisTarget target in _pendingFutureTargets.keys) {
- CacheEntry cacheEntry = _cache.get(target);
- List<PendingFuture> pendingFutures = _pendingFutureTargets[target];
- for (int i = 0; i < pendingFutures.length;) {
- if (pendingFutures[i].evaluate(cacheEntry)) {
- pendingFutures.removeAt(i);
- } else {
- i++;
- }
- }
- }
- }
-
@override
void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
elementMap.forEach((Source librarySource, LibraryElement library) {
@@ -1327,6 +1318,19 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
/**
+ * Return `true` if the given list of [sources] contains any of the given
+ * [targetSources].
+ */
+ bool _containsAny(List<Source> sources, List<Source> targetSources) {
+ for (Source targetSource in targetSources) {
+ if (_contains(sources, targetSource)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Set the contents of the given [source] to the given [contents] and mark the
* source as having changed. The additional [offset], [oldLength] and
* [newLength] information is used by the context to determine what reanalysis
@@ -1402,6 +1406,20 @@ class AnalysisContextImpl implements InternalAnalysisContext {
return entries;
}
+ void _evaluatePendingFutures() {
+ for (AnalysisTarget target in _pendingFutureTargets.keys) {
+ CacheEntry cacheEntry = _cache.get(target);
+ List<PendingFuture> pendingFutures = _pendingFutureTargets[target];
+ for (int i = 0; i < pendingFutures.length;) {
+ if (pendingFutures[i].evaluate(cacheEntry)) {
+ pendingFutures.removeAt(i);
+ } else {
+ i++;
+ }
+ }
+ }
+ }
+
/**
* Return a list containing all of the change notices that are waiting to be
* returned. If there are no notices, then return either `null` or an empty
@@ -1425,11 +1443,22 @@ class AnalysisContextImpl implements InternalAnalysisContext {
*/
List<Source> _getSources(SourceKind kind) {
List<Source> sources = <Source>[];
- for (Source source in _cache.sources) {
- CacheEntry entry = _cache.get(source);
- if (entry.getValue(SOURCE_KIND) == kind) {
- sources.add(source);
+ if (kind == SourceKind.LIBRARY || kind == SourceKind.PART) {
+ for (Source source in _cache.sources) {
+ CacheEntry entry = _cache.get(source);
+ if (entry.getValue(SOURCE_KIND) == kind) {
+ sources.add(source);
+ }
}
+ } else if (kind == SourceKind.HTML) {
+ for (Source source in _cache.sources) {
+ if (AnalysisEngine.isHtmlFileName(source.shortName)) {
+ sources.add(source);
+ }
+ }
+ }
+ if (sources == null) {
+ return Source.EMPTY_LIST;
Paul Berry 2015/06/15 21:34:38 Unreachable code. Sources will never be null. Se
Brian Wilkerson 2015/06/16 16:28:08 Done
}
return sources;
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.dart » ('j') | pkg/analyzer/lib/src/generated/engine.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698