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

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

Issue 1427513003: Compute documentation offsets for library, import, and export directive elements (issue 24756) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index ff360386f24a8aec8f976b2285f082673b6cf42e..b358fd36c08e77bc0d674ac7f445fcd93a4331c1 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -812,6 +812,7 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
importElement.deferred = importDirective.deferredKeyword != null;
importElement.combinators = _buildCombinators(importDirective);
importElement.importedLibrary = importedLibrary;
+ _setDocRange(importElement, importDirective);
SimpleIdentifier prefixNode = directive.prefix;
if (prefixNode != null) {
importElement.prefixOffset = prefixNode.offset;
@@ -853,6 +854,7 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
exportElement.uri = exportDirective.uriContent;
exportElement.combinators = _buildCombinators(exportDirective);
exportElement.exportedLibrary = exportedLibrary;
+ _setDocRange(exportElement, exportDirective);
directive.element = exportElement;
exports.add(exportElement);
if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
@@ -893,6 +895,17 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
}
/**
+ * If the given [node] has a documentation comment, remember its range
+ * into the given [element].
+ */
+ void _setDocRange(ElementImpl element, AnnotatedNode node) {
+ Comment comment = node.documentationComment;
+ if (comment != null && comment.isDocumentation) {
+ element.setDocRange(comment.offset, comment.length);
+ }
+ }
+
+ /**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the
* given library [libSource].
@@ -1161,6 +1174,7 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
//
// Update "part" directives.
//
+ LibraryDirective libraryDirective = null;
LibraryIdentifier libraryNameNode = null;
String partsLibraryName = _UNKNOWN_LIBRARY_NAME;
bool hasPartDirective = false;
@@ -1171,7 +1185,8 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
<CompilationUnitElementImpl>[];
for (Directive directive in definingCompilationUnit.directives) {
if (directive is LibraryDirective) {
- if (libraryNameNode == null) {
+ if (libraryDirective == null) {
+ libraryDirective = directive;
libraryNameNode = directive.name;
directivesToResolve.add(directive);
}
@@ -1255,6 +1270,9 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
if (sourcedCompilationUnits.isNotEmpty) {
_patchTopLevelAccessors(libraryElement);
}
+ if (libraryDirective != null) {
+ _setDocRange(libraryElement, libraryDirective);
+ }
//
// Record outputs.
//
@@ -1341,6 +1359,17 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
}
/**
+ * If the given [node] has a documentation comment, remember its range
+ * into the given [element].
+ */
+ void _setDocRange(ElementImpl element, AnnotatedNode node) {
+ Comment comment = node.documentationComment;
+ if (comment != null && comment.isDocumentation) {
+ element.setDocRange(comment.offset, comment.length);
+ }
+ }
+
+ /**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the given
* [libSource].
@@ -2125,11 +2154,9 @@ class DartErrorsTask extends SourceBasedAnalysisTask {
String inputName = result.name + '_input';
Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName);
for (List<AnalysisError> errors in errorMap.values) {
- errorLists.add(errors
- .where((AnalysisError error) {
- return !filters.any((ErrorFilter filter) => filter(error));
- })
- .toList());
+ errorLists.add(errors.where((AnalysisError error) {
+ return !filters.any((ErrorFilter filter) => filter(error));
+ }).toList());
}
}
//
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698