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

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

Issue 2362873002: Add some errors related to nnbd (Closed)
Patch Set: fixed error range Created 4 years, 3 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.src.generated.parser; 5 library analyzer.src.generated.parser;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 * parsed. 2743 * parsed.
2744 * 2744 *
2745 * This method assumes that the current token matches `Keyword.EXTENDS`. 2745 * This method assumes that the current token matches `Keyword.EXTENDS`.
2746 * 2746 *
2747 * classExtendsClause ::= 2747 * classExtendsClause ::=
2748 * 'extends' type 2748 * 'extends' type
2749 */ 2749 */
2750 ExtendsClause parseExtendsClause() { 2750 ExtendsClause parseExtendsClause() {
2751 Token keyword = getAndAdvance(); 2751 Token keyword = getAndAdvance();
2752 TypeName superclass = parseTypeName(false); 2752 TypeName superclass = parseTypeName(false);
2753 _mustNotBeNullable(superclass, ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS);
2753 return new ExtendsClause(keyword, superclass); 2754 return new ExtendsClause(keyword, superclass);
2754 } 2755 }
2755 2756
2756 /** 2757 /**
2757 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. 2758 * Parse the 'final', 'const', 'var' or type preceding a variable declaration.
2758 * The [optional] is `true` if the keyword and type are optional. Return the 2759 * The [optional] is `true` if the keyword and type are optional. Return the
2759 * 'final', 'const', 'var' or type that was parsed. 2760 * 'final', 'const', 'var' or type that was parsed.
2760 * 2761 *
2761 * finalConstVarOrType ::= 2762 * finalConstVarOrType ::=
2762 * 'final' type? 2763 * 'final' type?
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 * Parse an implements clause. Return the implements clause that was parsed. 3355 * Parse an implements clause. Return the implements clause that was parsed.
3355 * 3356 *
3356 * This method assumes that the current token matches `Keyword.IMPLEMENTS`. 3357 * This method assumes that the current token matches `Keyword.IMPLEMENTS`.
3357 * 3358 *
3358 * implementsClause ::= 3359 * implementsClause ::=
3359 * 'implements' type (',' type)* 3360 * 'implements' type (',' type)*
3360 */ 3361 */
3361 ImplementsClause parseImplementsClause() { 3362 ImplementsClause parseImplementsClause() {
3362 Token keyword = getAndAdvance(); 3363 Token keyword = getAndAdvance();
3363 List<TypeName> interfaces = <TypeName>[]; 3364 List<TypeName> interfaces = <TypeName>[];
3364 interfaces.add(parseTypeName(false)); 3365 do {
3365 while (_optional(TokenType.COMMA)) { 3366 TypeName typeName = parseTypeName(false);
3366 interfaces.add(parseTypeName(false)); 3367 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS);
3367 } 3368 interfaces.add(typeName);
3369 } while (_optional(TokenType.COMMA));
3368 return new ImplementsClause(keyword, interfaces); 3370 return new ImplementsClause(keyword, interfaces);
3369 } 3371 }
3370 3372
3371 /** 3373 /**
3372 * Parse an import directive. The [commentAndMetadata] is the metadata to be 3374 * Parse an import directive. The [commentAndMetadata] is the metadata to be
3373 * associated with the directive. Return the import directive that was parsed. 3375 * associated with the directive. Return the import directive that was parsed.
3374 * 3376 *
3375 * This method assumes that the current token matches `Keyword.IMPORT`. 3377 * This method assumes that the current token matches `Keyword.IMPORT`.
3376 * 3378 *
3377 * importDirective ::= 3379 * importDirective ::=
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after
4920 4922
4921 /** 4923 /**
4922 * Parse a type parameter. Return the type parameter that was parsed. 4924 * Parse a type parameter. Return the type parameter that was parsed.
4923 * 4925 *
4924 * typeParameter ::= 4926 * typeParameter ::=
4925 * metadata name ('extends' bound)? 4927 * metadata name ('extends' bound)?
4926 */ 4928 */
4927 TypeParameter parseTypeParameter() { 4929 TypeParameter parseTypeParameter() {
4928 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4930 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4929 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true); 4931 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
4932 if (_matches(TokenType.QUESTION)) {
4933 _reportErrorForCurrentToken(ParserErrorCode.NULLABLE_TYPE_PARAMETER);
4934 _advance();
4935 }
4930 if (_matchesKeyword(Keyword.EXTENDS)) { 4936 if (_matchesKeyword(Keyword.EXTENDS)) {
4931 Token keyword = getAndAdvance(); 4937 Token keyword = getAndAdvance();
4932 TypeName bound = parseTypeName(false); 4938 TypeName bound = parseTypeName(false);
4933 return new TypeParameter(commentAndMetadata.comment, 4939 return new TypeParameter(commentAndMetadata.comment,
4934 commentAndMetadata.metadata, name, keyword, bound); 4940 commentAndMetadata.metadata, name, keyword, bound);
4935 } 4941 }
4936 return new TypeParameter(commentAndMetadata.comment, 4942 return new TypeParameter(commentAndMetadata.comment,
4937 commentAndMetadata.metadata, name, null, null); 4943 commentAndMetadata.metadata, name, null, null);
4938 } 4944 }
4939 4945
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
5153 /** 5159 /**
5154 * Parse a with clause. Return the with clause that was parsed. 5160 * Parse a with clause. Return the with clause that was parsed.
5155 * 5161 *
5156 * This method assumes that the current token matches `Keyword.WITH`. 5162 * This method assumes that the current token matches `Keyword.WITH`.
5157 * 5163 *
5158 * withClause ::= 5164 * withClause ::=
5159 * 'with' typeName (',' typeName)* 5165 * 'with' typeName (',' typeName)*
5160 */ 5166 */
5161 WithClause parseWithClause() { 5167 WithClause parseWithClause() {
5162 Token withKeyword = getAndAdvance(); 5168 Token withKeyword = getAndAdvance();
5163 List<TypeName> types = <TypeName>[parseTypeName(false)]; 5169 List<TypeName> types = <TypeName>[];
5164 while (_optional(TokenType.COMMA)) { 5170 do {
5165 types.add(parseTypeName(false)); 5171 TypeName typeName = parseTypeName(false);
5166 } 5172 _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_WITH);
5173 types.add(typeName);
5174 } while (_optional(TokenType.COMMA));
5167 return new WithClause(withKeyword, types); 5175 return new WithClause(withKeyword, types);
5168 } 5176 }
5169 5177
5170 /** 5178 /**
5171 * Parse a yield statement. Return the yield statement that was parsed. 5179 * Parse a yield statement. Return the yield statement that was parsed.
5172 * 5180 *
5173 * This method assumes that the current token matches [Keyword.YIELD]. 5181 * This method assumes that the current token matches [Keyword.YIELD].
5174 * 5182 *
5175 * yieldStatement ::= 5183 * yieldStatement ::=
5176 * 'yield' '*'? expression ';' 5184 * 'yield' '*'? expression ';'
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
5947 _tokenMatchesKeyword(_currentToken, keyword); 5955 _tokenMatchesKeyword(_currentToken, keyword);
5948 5956
5949 /** 5957 /**
5950 * Return `true` if the current token matches the given [identifier]. 5958 * Return `true` if the current token matches the given [identifier].
5951 */ 5959 */
5952 bool _matchesString(String identifier) => 5960 bool _matchesString(String identifier) =>
5953 _currentToken.type == TokenType.IDENTIFIER && 5961 _currentToken.type == TokenType.IDENTIFIER &&
5954 _currentToken.lexeme == identifier; 5962 _currentToken.lexeme == identifier;
5955 5963
5956 /** 5964 /**
5965 * Report an error with the given [errorCode] if the given [typeName] has been
5966 * marked as nullable.
5967 */
5968 void _mustNotBeNullable(TypeName typeName, ParserErrorCode errorCode) {
5969 if (typeName.question != null) {
5970 _reportErrorForToken(errorCode, typeName.question);
5971 }
5972 }
5973
5974 /**
5957 * If the current token has the given [type], then advance to the next token 5975 * If the current token has the given [type], then advance to the next token
5958 * and return `true`. Otherwise, return `false` without advancing. This method 5976 * and return `true`. Otherwise, return `false` without advancing. This method
5959 * should not be invoked with an argument value of [TokenType.GT]. 5977 * should not be invoked with an argument value of [TokenType.GT].
5960 */ 5978 */
5961 bool _optional(TokenType type) { 5979 bool _optional(TokenType type) {
5962 if (_currentToken.type == type) { 5980 if (_currentToken.type == type) {
5963 _advance(); 5981 _advance();
5964 return true; 5982 return true;
5965 } 5983 }
5966 return false; 5984 return false;
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after
8616 "Enclose the URI in either single or double quotes."); 8634 "Enclose the URI in either single or double quotes.");
8617 8635
8618 static const ParserErrorCode NON_USER_DEFINABLE_OPERATOR = 8636 static const ParserErrorCode NON_USER_DEFINABLE_OPERATOR =
8619 const ParserErrorCode('NON_USER_DEFINABLE_OPERATOR', 8637 const ParserErrorCode('NON_USER_DEFINABLE_OPERATOR',
8620 "The operator '{0}' is not user definable"); 8638 "The operator '{0}' is not user definable");
8621 8639
8622 static const ParserErrorCode NORMAL_BEFORE_OPTIONAL_PARAMETERS = 8640 static const ParserErrorCode NORMAL_BEFORE_OPTIONAL_PARAMETERS =
8623 const ParserErrorCode('NORMAL_BEFORE_OPTIONAL_PARAMETERS', 8641 const ParserErrorCode('NORMAL_BEFORE_OPTIONAL_PARAMETERS',
8624 "Normal parameters must occur before optional parameters"); 8642 "Normal parameters must occur before optional parameters");
8625 8643
8644 static const ParserErrorCode NULLABLE_TYPE_IN_EXTENDS = const ParserErrorCode(
8645 'NULLABLE_TYPE_IN_EXTENDS',
8646 "A nullable type cannot be used in an extends clause",
8647 "Remove the '?' from the type name");
8648
8649 static const ParserErrorCode NULLABLE_TYPE_IN_IMPLEMENTS =
8650 const ParserErrorCode(
8651 'NULLABLE_TYPE_IN_IMPLEMENTS',
8652 "A nullable type cannot be used in an implements clause",
8653 "Remove the '?' from the type name");
8654
8655 static const ParserErrorCode NULLABLE_TYPE_IN_WITH = const ParserErrorCode(
8656 'NULLABLE_TYPE_IN_WITH',
8657 "A nullable type cannot be used in an with clause",
scheglov 2016/09/22 20:30:43 "a with"?
Brian Wilkerson 2016/09/22 20:43:13 Done
8658 "Remove the '?' from the type name");
8659
8660 static const ParserErrorCode NULLABLE_TYPE_PARAMETER = const ParserErrorCode(
8661 'NULLABLE_TYPE_PARAMETER',
8662 "Type parameters cannot be nullable",
8663 "Remove the '?' from the type name");
8664
8626 static const ParserErrorCode POSITIONAL_AFTER_NAMED_ARGUMENT = 8665 static const ParserErrorCode POSITIONAL_AFTER_NAMED_ARGUMENT =
8627 const ParserErrorCode('POSITIONAL_AFTER_NAMED_ARGUMENT', 8666 const ParserErrorCode('POSITIONAL_AFTER_NAMED_ARGUMENT',
8628 "Positional arguments must occur before named arguments"); 8667 "Positional arguments must occur before named arguments");
8629 8668
8630 static const ParserErrorCode POSITIONAL_PARAMETER_OUTSIDE_GROUP = 8669 static const ParserErrorCode POSITIONAL_PARAMETER_OUTSIDE_GROUP =
8631 const ParserErrorCode('POSITIONAL_PARAMETER_OUTSIDE_GROUP', 8670 const ParserErrorCode('POSITIONAL_PARAMETER_OUTSIDE_GROUP',
8632 "Positional parameters must be enclosed in square brackets ('[' and '] ')"); 8671 "Positional parameters must be enclosed in square brackets ('[' and '] ')");
8633 8672
8634 static const ParserErrorCode REDIRECTING_CONSTRUCTOR_WITH_BODY = 8673 static const ParserErrorCode REDIRECTING_CONSTRUCTOR_WITH_BODY =
8635 const ParserErrorCode('REDIRECTING_CONSTRUCTOR_WITH_BODY', 8674 const ParserErrorCode('REDIRECTING_CONSTRUCTOR_WITH_BODY',
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
8748 */ 8787 */
8749 const ParserErrorCode(String name, String message, [String correction]) 8788 const ParserErrorCode(String name, String message, [String correction])
8750 : super(name, message, correction); 8789 : super(name, message, correction);
8751 8790
8752 @override 8791 @override
8753 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; 8792 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
8754 8793
8755 @override 8794 @override
8756 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 8795 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
8757 } 8796 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698