OLD | NEW |
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 analyzer.src.dart.ast.token; | 5 library analyzer.src.dart.ast.token; |
6 | 6 |
7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
8 import 'package:analyzer/src/generated/java_engine.dart'; | 8 import 'package:analyzer/src/generated/java_engine.dart'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 17 matching lines...) Expand all Loading... |
28 type == TokenType.STRING_INTERPOLATION_EXPRESSION); | 28 type == TokenType.STRING_INTERPOLATION_EXPRESSION); |
29 } | 29 } |
30 | 30 |
31 @override | 31 @override |
32 Token copy() => new BeginToken(type, offset); | 32 Token copy() => new BeginToken(type, offset); |
33 } | 33 } |
34 | 34 |
35 /** | 35 /** |
36 * A begin token that is preceded by comments. | 36 * A begin token that is preceded by comments. |
37 */ | 37 */ |
38 class BeginTokenWithComment extends BeginToken { | 38 class BeginTokenWithComment extends BeginToken implements TokenWithComment { |
39 /** | 39 /** |
40 * The first comment in the list of comments that precede this token. | 40 * The first comment in the list of comments that precede this token. |
41 */ | 41 */ |
42 CommentToken _precedingComment; | 42 CommentToken _precedingComment; |
43 | 43 |
44 /** | 44 /** |
45 * Initialize a newly created token to have the given [type] at the given | 45 * Initialize a newly created token to have the given [type] at the given |
46 * [offset] and to be preceded by the comments reachable from the given | 46 * [offset] and to be preceded by the comments reachable from the given |
47 * [comment]. | 47 * [comment]. |
48 */ | 48 */ |
(...skipping 23 matching lines...) Expand all Loading... |
72 @override | 72 @override |
73 Token copy() => | 73 Token copy() => |
74 new BeginTokenWithComment(type, offset, copyComments(precedingComments)); | 74 new BeginTokenWithComment(type, offset, copyComments(precedingComments)); |
75 } | 75 } |
76 | 76 |
77 /** | 77 /** |
78 * A token representing a comment. | 78 * A token representing a comment. |
79 */ | 79 */ |
80 class CommentToken extends StringToken { | 80 class CommentToken extends StringToken { |
81 /** | 81 /** |
82 * The [Token] that contains this comment. | 82 * The token that contains this comment. |
83 */ | 83 */ |
84 Token parent; | 84 TokenWithComment parent; |
85 | 85 |
86 /** | 86 /** |
87 * Initialize a newly created token to represent a token of the given [type] | 87 * Initialize a newly created token to represent a token of the given [type] |
88 * with the given [value] at the given [offset]. | 88 * with the given [value] at the given [offset]. |
89 */ | 89 */ |
90 CommentToken(TokenType type, String value, int offset) | 90 CommentToken(TokenType type, String value, int offset) |
91 : super(type, value, offset); | 91 : super(type, value, offset); |
92 | 92 |
93 @override | 93 @override |
94 CommentToken copy() => new CommentToken(type, _value, offset); | 94 CommentToken copy() => new CommentToken(type, _value, offset); |
| 95 |
| 96 /** |
| 97 * Remove this comment token from the list. |
| 98 * |
| 99 * This is used when we decide to interpret the comment as syntax. |
| 100 */ |
| 101 void remove() { |
| 102 if (previous != null) { |
| 103 previous.setNextWithoutSettingPrevious(next); |
| 104 next?.previous = previous; |
| 105 } else { |
| 106 assert(parent.precedingComments == this); |
| 107 parent.precedingComments = next; |
| 108 } |
| 109 } |
95 } | 110 } |
96 | 111 |
97 /** | 112 /** |
98 * A documentation comment token. | 113 * A documentation comment token. |
99 */ | 114 */ |
100 class DocumentationCommentToken extends CommentToken { | 115 class DocumentationCommentToken extends CommentToken { |
101 /** | 116 /** |
102 * The references embedded within the documentation comment. | 117 * The references embedded within the documentation comment. |
103 * This list will be empty unless this is a documentation comment that has | 118 * This list will be empty unless this is a documentation comment that has |
104 * references embedded within it. | 119 * references embedded within it. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 @override | 157 @override |
143 Token copy() => new KeywordToken(keyword, offset); | 158 Token copy() => new KeywordToken(keyword, offset); |
144 | 159 |
145 @override | 160 @override |
146 Keyword value() => keyword; | 161 Keyword value() => keyword; |
147 } | 162 } |
148 | 163 |
149 /** | 164 /** |
150 * A keyword token that is preceded by comments. | 165 * A keyword token that is preceded by comments. |
151 */ | 166 */ |
152 class KeywordTokenWithComment extends KeywordToken { | 167 class KeywordTokenWithComment extends KeywordToken implements TokenWithComment { |
153 /** | 168 /** |
154 * The first comment in the list of comments that precede this token. | 169 * The first comment in the list of comments that precede this token. |
155 */ | 170 */ |
156 CommentToken _precedingComment; | 171 CommentToken _precedingComment; |
157 | 172 |
158 /** | 173 /** |
159 * Initialize a newly created token to to represent the given [keyword] at the | 174 * Initialize a newly created token to to represent the given [keyword] at the |
160 * given [offset] and to be preceded by the comments reachable from the given | 175 * given [offset] and to be preceded by the comments reachable from the given |
161 * [comment]. | 176 * [comment]. |
162 */ | 177 */ |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 @override | 348 @override |
334 Token copy() => new StringToken(type, _value, offset); | 349 Token copy() => new StringToken(type, _value, offset); |
335 | 350 |
336 @override | 351 @override |
337 String value() => _value; | 352 String value() => _value; |
338 } | 353 } |
339 | 354 |
340 /** | 355 /** |
341 * A string token that is preceded by comments. | 356 * A string token that is preceded by comments. |
342 */ | 357 */ |
343 class StringTokenWithComment extends StringToken { | 358 class StringTokenWithComment extends StringToken implements TokenWithComment { |
344 /** | 359 /** |
345 * The first comment in the list of comments that precede this token. | 360 * The first comment in the list of comments that precede this token. |
346 */ | 361 */ |
347 CommentToken _precedingComment; | 362 CommentToken _precedingComment; |
348 | 363 |
349 /** | 364 /** |
350 * Initialize a newly created token to have the given [type] at the given | 365 * Initialize a newly created token to have the given [type] at the given |
351 * [offset] and to be preceded by the comments reachable from the given | 366 * [offset] and to be preceded by the comments reachable from the given |
352 * [comment]. | 367 * [comment]. |
353 */ | 368 */ |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 CommentToken get precedingComments => _precedingComment; | 560 CommentToken get precedingComments => _precedingComment; |
546 | 561 |
547 void set precedingComments(CommentToken comment) { | 562 void set precedingComments(CommentToken comment) { |
548 _precedingComment = comment; | 563 _precedingComment = comment; |
549 _setCommentParent(_precedingComment); | 564 _setCommentParent(_precedingComment); |
550 } | 565 } |
551 | 566 |
552 @override | 567 @override |
553 Token copy() => new TokenWithComment(type, offset, precedingComments); | 568 Token copy() => new TokenWithComment(type, offset, precedingComments); |
554 } | 569 } |
OLD | NEW |