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

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

Issue 1423993005: Quick Fix for CAN_BE_NULL_AFTER_NULL_AWARE. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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.resolver; 5 library engine.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/src/generated/scanner.dart';
10 10
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 @override 212 @override
213 Object visitMethodDeclaration(MethodDeclaration node) { 213 Object visitMethodDeclaration(MethodDeclaration node) {
214 // This was determined to not be a good hint, see: dartbug.com/16029 214 // This was determined to not be a good hint, see: dartbug.com/16029
215 //checkForOverridingPrivateMember(node); 215 //checkForOverridingPrivateMember(node);
216 _checkForMissingReturn(node.returnType, node.body); 216 _checkForMissingReturn(node.returnType, node.body);
217 return super.visitMethodDeclaration(node); 217 return super.visitMethodDeclaration(node);
218 } 218 }
219 219
220 @override 220 @override
221 Object visitMethodInvocation(MethodInvocation node) { 221 Object visitMethodInvocation(MethodInvocation node) {
222 _checkForCanBeNullAfterNullAware(node.realTarget); 222 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator);
223 return super.visitMethodInvocation(node); 223 return super.visitMethodInvocation(node);
224 } 224 }
225 225
226 @override 226 @override
227 Object visitPostfixExpression(PostfixExpression node) { 227 Object visitPostfixExpression(PostfixExpression node) {
228 _checkForDeprecatedMemberUse(node.bestElement, node); 228 _checkForDeprecatedMemberUse(node.bestElement, node);
229 return super.visitPostfixExpression(node); 229 return super.visitPostfixExpression(node);
230 } 230 }
231 231
232 @override 232 @override
233 Object visitPrefixExpression(PrefixExpression node) { 233 Object visitPrefixExpression(PrefixExpression node) {
234 _checkForDeprecatedMemberUse(node.bestElement, node); 234 _checkForDeprecatedMemberUse(node.bestElement, node);
235 return super.visitPrefixExpression(node); 235 return super.visitPrefixExpression(node);
236 } 236 }
237 237
238 @override 238 @override
239 Object visitPropertyAccess(PropertyAccess node) { 239 Object visitPropertyAccess(PropertyAccess node) {
240 _checkForCanBeNullAfterNullAware(node.realTarget); 240 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator);
241 return super.visitPropertyAccess(node); 241 return super.visitPropertyAccess(node);
242 } 242 }
243 243
244 @override 244 @override
245 Object visitRedirectingConstructorInvocation( 245 Object visitRedirectingConstructorInvocation(
246 RedirectingConstructorInvocation node) { 246 RedirectingConstructorInvocation node) {
247 _checkForDeprecatedMemberUse(node.staticElement, node); 247 _checkForDeprecatedMemberUse(node.staticElement, node);
248 return super.visitRedirectingConstructorInvocation(node); 248 return super.visitRedirectingConstructorInvocation(node);
249 } 249 }
250 250
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 bool problemReported = false; 458 bool problemReported = false;
459 for (Expression argument in argumentList.arguments) { 459 for (Expression argument in argumentList.arguments) {
460 if (_checkForArgumentTypeNotAssignableForArgument(argument)) { 460 if (_checkForArgumentTypeNotAssignableForArgument(argument)) {
461 problemReported = true; 461 problemReported = true;
462 } 462 }
463 } 463 }
464 return problemReported; 464 return problemReported;
465 } 465 }
466 466
467 /** 467 /**
468 * Produce a hint if the given [expression] could have a value of `null`. 468 * Produce a hint if the given [target] could have a value of `null`.
469 */ 469 */
470 void _checkForCanBeNullAfterNullAware(Expression expression) { 470 void _checkForCanBeNullAfterNullAware(Expression target, Token operator) {
471 if (expression is ParenthesizedExpression) { 471 if (operator?.type == TokenType.QUESTION_PERIOD) {
Brian Wilkerson 2015/10/29 14:02:23 It seems strange to have to repeat this test for a
472 _checkForCanBeNullAfterNullAware(expression.expression); 472 return;
473 } else if (expression is MethodInvocation) { 473 }
474 if (expression.operator?.type == TokenType.QUESTION_PERIOD) { 474 if (target is ParenthesizedExpression) {
475 _checkForCanBeNullAfterNullAware(target.expression, operator);
476 } else if (target is MethodInvocation) {
477 if (target.operator?.type == TokenType.QUESTION_PERIOD) {
475 _errorReporter.reportErrorForNode( 478 _errorReporter.reportErrorForNode(
476 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, expression); 479 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target);
477 } 480 }
478 } else if (expression is PropertyAccess) { 481 } else if (target is PropertyAccess) {
479 if (expression.operator.type == TokenType.QUESTION_PERIOD) { 482 if (target.operator.type == TokenType.QUESTION_PERIOD) {
480 _errorReporter.reportErrorForNode( 483 _errorReporter.reportErrorForNode(
481 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, expression); 484 HintCode.CAN_BE_NULL_AFTER_NULL_AWARE, target);
482 } 485 }
483 } 486 }
484 } 487 }
485 488
486 /** 489 /**
487 * Given some [Element], look at the associated metadata and report the use of the member if 490 * Given some [Element], look at the associated metadata and report the use of the member if
488 * it is declared as deprecated. 491 * it is declared as deprecated.
489 * 492 *
490 * @param element some element to check for deprecated use of 493 * @param element some element to check for deprecated use of
491 * @param node the node use for the location of the error 494 * @param node the node use for the location of the error
(...skipping 15603 matching lines...) Expand 10 before | Expand all | Expand 10 after
16095 nonFields.add(node); 16098 nonFields.add(node);
16096 return null; 16099 return null;
16097 } 16100 }
16098 16101
16099 @override 16102 @override
16100 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 16103 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
16101 16104
16102 @override 16105 @override
16103 Object visitWithClause(WithClause node) => null; 16106 Object visitWithClause(WithClause node) => null;
16104 } 16107 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/correction/fix_test.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698