| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * The cached lookup-table to associate doc comments with spans. The outer map | 6 * The cached lookup-table to associate doc comments with spans. The outer map |
| 7 * is from filenames to doc comments in that file. The inner map maps from the | 7 * is from filenames to doc comments in that file. The inner map maps from the |
| 8 * token positions to doc comments. Each position is the starting offset of the | 8 * token positions to doc comments. Each position is the starting offset of the |
| 9 * next non-comment token *following* the doc comment. For example, the position | 9 * next non-comment token *following* the doc comment. For example, the position |
| 10 * for this comment would be the position of the "class" token below. | 10 * for this comment would be the position of the "class" token below. |
| 11 */ | 11 */ |
| 12 class CommentMap { | 12 class CommentMap { |
| 13 /** | 13 /** |
| 14 * Maps from (filename, pos) to doc comment preceding the token at that | 14 * Maps from (filename, pos) to doc comment preceding the token at that |
| 15 * position. | 15 * position. |
| 16 */ | 16 */ |
| 17 Map<String, Map<int, String>> _comments; | 17 Map<String, Map<int, String>> _comments; |
| 18 | 18 |
| 19 /** Doc comments before #library() directives. */ | 19 /** Doc comments before #library() directives. */ |
| 20 Map<String, String> _libraryComments; | 20 Map<String, String> _libraryComments; |
| 21 | 21 |
| 22 CommentMap() | 22 CommentMap() |
| 23 : _comments = <Map<int, String>>{}, | 23 : _comments = <String, Map<int, String>>{}, |
| 24 _libraryComments = <String>{}; | 24 _libraryComments = <String, String>{}; |
| 25 | 25 |
| 26 /** Finds the doc comment preceding the given source span, if there is one. */ | 26 /** Finds the doc comment preceding the given source span, if there is one. */ |
| 27 String find(Location span) { | 27 String find(Location span) { |
| 28 if (span == null) return null; | 28 if (span == null) return null; |
| 29 | 29 |
| 30 _ensureFileParsed(span.source); | 30 _ensureFileParsed(span.source); |
| 31 final comment = _comments[span.source.uri.toString()][span.start]; | 31 final comment = _comments[span.source.uri.toString()][span.start]; |
| 32 if (comment == null) return ''; | 32 if (comment == null) return ''; |
| 33 return comment; | 33 return comment; |
| 34 } | 34 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 line = line.substring(1); | 109 line = line.substring(1); |
| 110 } | 110 } |
| 111 | 111 |
| 112 buf.add(line); | 112 buf.add(line); |
| 113 buf.add('\n'); | 113 buf.add('\n'); |
| 114 } | 114 } |
| 115 | 115 |
| 116 return buf.toString(); | 116 return buf.toString(); |
| 117 } | 117 } |
| 118 } | 118 } |
| OLD | NEW |