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

Side by Side Diff: pkg/analyzer/lib/src/generated/engine.dart

Issue 1376473007: Add the 'docRange' property and use it to compute documentation comment. (Closed) Base URL: git@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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine; 5 library engine;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:math' as math; 9 import 'dart:math' as math;
10 10
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 1634
1635 @override 1635 @override
1636 String computeDocumentationComment(Element element) { 1636 String computeDocumentationComment(Element element) {
1637 if (element == null) { 1637 if (element == null) {
1638 return null; 1638 return null;
1639 } 1639 }
1640 Source source = element.source; 1640 Source source = element.source;
1641 if (source == null) { 1641 if (source == null) {
1642 return null; 1642 return null;
1643 } 1643 }
1644 CompilationUnit unit = parseCompilationUnit(source); 1644 SourceRange docRange = element.docRange;
1645 if (unit == null) { 1645 if (docRange == null) {
1646 return null; 1646 return null;
1647 } 1647 }
1648 NodeLocator locator = new NodeLocator(element.nameOffset); 1648 String code = getContents(source).data;
1649 AstNode nameNode = locator.searchWithin(unit); 1649 String comment = code.substring(docRange.offset, docRange.end);
1650 while (nameNode != null) { 1650 return comment.replaceAll('\r\n', '\n');
1651 if (nameNode is AnnotatedNode) {
1652 Comment comment = nameNode.documentationComment;
1653 if (comment == null) {
1654 return null;
1655 }
1656 StringBuffer buffer = new StringBuffer();
1657 List<Token> tokens = comment.tokens;
1658 for (int i = 0; i < tokens.length; i++) {
1659 if (i > 0) {
1660 buffer.write("\n");
1661 }
1662 buffer.write(tokens[i].lexeme);
1663 }
1664 return buffer.toString();
1665 }
1666 nameNode = nameNode.parent;
1667 }
1668 return null;
1669 } 1651 }
1670 1652
1671 @override 1653 @override
1672 List<AnalysisError> computeErrors(Source source) { 1654 List<AnalysisError> computeErrors(Source source) {
1673 bool enableHints = _options.hint; 1655 bool enableHints = _options.hint;
1674 bool enableLints = _options.lint; 1656 bool enableLints = _options.lint;
1675 1657
1676 SourceEntry sourceEntry = _getReadableSourceEntry(source); 1658 SourceEntry sourceEntry = _getReadableSourceEntry(source);
1677 if (sourceEntry is DartEntry) { 1659 if (sourceEntry is DartEntry) {
1678 List<AnalysisError> errors = new List<AnalysisError>(); 1660 List<AnalysisError> errors = new List<AnalysisError>();
(...skipping 10391 matching lines...) Expand 10 before | Expand all | Expand 10 after
12070 PendingFuture pendingFuture = 12052 PendingFuture pendingFuture =
12071 new PendingFuture<T>(_context, source, computeValue); 12053 new PendingFuture<T>(_context, source, computeValue);
12072 if (!pendingFuture.evaluate(sourceEntry)) { 12054 if (!pendingFuture.evaluate(sourceEntry)) {
12073 _context._pendingFutureSources 12055 _context._pendingFutureSources
12074 .putIfAbsent(source, () => <PendingFuture>[]) 12056 .putIfAbsent(source, () => <PendingFuture>[])
12075 .add(pendingFuture); 12057 .add(pendingFuture);
12076 } 12058 }
12077 return pendingFuture.future; 12059 return pendingFuture.future;
12078 } 12060 }
12079 } 12061 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_handle.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698