Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/scanner.dart |
| diff --git a/pkg/analyzer/lib/src/generated/scanner.dart b/pkg/analyzer/lib/src/generated/scanner.dart |
| index 0a9fa2a106ac940cee56163d48b3e72df1001f09..e765462e93b3ffff69f441afdbe06768d44e22e9 100644 |
| --- a/pkg/analyzer/lib/src/generated/scanner.dart |
| +++ b/pkg/analyzer/lib/src/generated/scanner.dart |
| @@ -246,6 +246,19 @@ class CommentToken extends StringToken { |
| CommentToken copy() => new CommentToken(type, _value, offset); |
| } |
| +class GenericMethodCommentToken extends CommentToken { |
|
Brian Wilkerson
2015/11/11 21:53:42
It isn't clear to me that we need a separate class
Jennifer Messerly
2015/11/12 00:20:00
Good catch. Yeah I think my order was I made the c
|
| + /** |
| + * Initialize a newly created token to represent a token of the given [type] |
| + * with the given [value] at the given [offset]. |
| + */ |
| + GenericMethodCommentToken(TokenType type, String value, int offset) |
| + : super(type, value, offset); |
| + |
| + @override |
| + GenericMethodCommentToken copy() => |
| + new GenericMethodCommentToken(type, _value, offset); |
| +} |
| + |
| /** |
| * A documentation comment token. |
| */ |
| @@ -723,6 +736,12 @@ class Scanner { |
| bool _hasUnmatchedGroups = false; |
| /** |
| + * A flag indicating whether to parse generic method comments, of the form |
|
Brian Wilkerson
2015/11/11 21:53:42
Maybe "parse" --> "scan" in both the comment and t
Jennifer Messerly
2015/11/12 00:20:00
Sounds good to me. Done.
|
| + * `/*=T*/` and `/*<T>*/`. |
| + */ |
| + bool parseGenericMethodComments = false; |
| + |
| + /** |
| * Initialize a newly created scanner to scan characters from the given |
| * [source]. The given character [_reader] will be used to read the characters |
| * in the source. The given [_errorListener] will be informed of any errors |
| @@ -1012,16 +1031,20 @@ class Scanner { |
| } |
| void _appendCommentToken(TokenType type, String value) { |
| - // Ignore comment tokens if client specified that it doesn't need them. |
| - if (!_preserveComments) { |
| + CommentToken token = null; |
| + TokenType genericComment = _matchGenericMethodCommentType(value); |
| + if (genericComment != null) { |
| + token = new GenericMethodCommentToken(genericComment, value, _tokenStart); |
| + } else if (!_preserveComments) { |
| + // Ignore comment tokens if client specified that it doesn't need them. |
| return; |
| - } |
| - // OK, remember comment tokens. |
| - CommentToken token; |
| - if (_isDocumentationComment(value)) { |
| - token = new DocumentationCommentToken(type, value, _tokenStart); |
| } else { |
| - token = new CommentToken(type, value, _tokenStart); |
| + // OK, remember comment tokens. |
| + if (_isDocumentationComment(value)) { |
| + token = new DocumentationCommentToken(type, value, _tokenStart); |
| + } else { |
| + token = new CommentToken(type, value, _tokenStart); |
| + } |
| } |
| if (_firstComment == null) { |
| _firstComment = token; |
| @@ -1820,6 +1843,27 @@ class Scanner { |
| return StringUtilities.startsWith3(value, 0, 0x2F, 0x2F, 0x2F) || |
| StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x2A); |
| } |
| + |
| + /** |
| + * Checks if [value] is the start of a generic method type annotation comment. |
| + * |
| + * This can either be of the form `/*<T>*/` or `/*=T*/`. The token type is |
| + * returned, or null if it was not a generic method comment. |
| + */ |
| + TokenType _matchGenericMethodCommentType(String value) { |
| + if (parseGenericMethodComments) { |
| + // Match /*< and >*/ |
| + if (StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x3C) && |
| + StringUtilities.endsWith3(value, 0x3E, 0x2A, 0x2F)) { |
| + return TokenType.GENERIC_METHOD_TYPE_LIST; |
| + } |
| + // Match /*= |
| + if (StringUtilities.startsWith3(value, 0, 0x2F, 0x2A, 0x3D)) { |
| + return TokenType.GENERIC_METHOD_TYPE_ASSIGN; |
| + } |
| + } |
| + return null; |
| + } |
| } |
| /** |
| @@ -2057,9 +2101,9 @@ class Token { |
| * comments can be reached by following the token stream using [next] until |
| * `null` is returned. |
| * |
| - * For example, if the original contents were "/* one */ /* two */ id", then |
| - * the first preceding comment token will have a lexeme of "/* one */" and |
| - * the next comment token will have a lexeme of "/* two */". |
| + * For example, if the original contents were `/* one */ /* two */ id`, then |
| + * the first preceding comment token will have a lexeme of `/* one */` and |
| + * the next comment token will have a lexeme of `/* two */`. |
| */ |
| CommentToken get precedingComments => null; |
| @@ -2501,6 +2545,12 @@ class TokenType { |
| static const TokenType PERIOD_PERIOD_PERIOD = |
| const TokenType('PERIOD_PERIOD_PERIOD', TokenClass.NO_CLASS, "..."); |
| + static const TokenType GENERIC_METHOD_TYPE_LIST = |
| + const TokenType('GENERIC_METHOD_TYPE_LIST'); |
| + |
| + static const TokenType GENERIC_METHOD_TYPE_ASSIGN = |
| + const TokenType('GENERIC_METHOD_TYPE_ASSIGN'); |
| + |
| /** |
| * The class of the token. |
| */ |