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

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

Issue 1427783003: Check for potential null operand in Not expressions. (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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_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 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 658
659 /** 659 /**
660 * Produce a hint if the given [condition] could have a value of `null`. 660 * Produce a hint if the given [condition] could have a value of `null`.
661 */ 661 */
662 void _checkForPossibleNullCondition(Expression condition) { 662 void _checkForPossibleNullCondition(Expression condition) {
663 while (condition is ParenthesizedExpression) { 663 while (condition is ParenthesizedExpression) {
664 condition = (condition as ParenthesizedExpression).expression; 664 condition = (condition as ParenthesizedExpression).expression;
665 } 665 }
666 if (condition is BinaryExpression) { 666 if (condition is BinaryExpression) {
667 _checkForPossibleNullConditionInBinaryExpression(condition); 667 _checkForPossibleNullConditionInBinaryExpression(condition);
668 } else if (condition is PrefixExpression) {
669 _checkForPossibleNullConditionInPrefixExpression(condition);
668 } else { 670 } else {
669 _checkForPossibleNullConditionInSimpleExpression(condition); 671 _checkForPossibleNullConditionInSimpleExpression(condition);
670 } 672 }
671 } 673 }
672 674
673 /** 675 /**
674 * Produce a hint if any of the parts of the given binary [condition] could 676 * Produce a hint if any of the parts of the given binary [condition] could
675 * have a value of `null`. 677 * have a value of `null`.
676 */ 678 */
677 void _checkForPossibleNullConditionInBinaryExpression( 679 void _checkForPossibleNullConditionInBinaryExpression(
678 BinaryExpression condition) { 680 BinaryExpression condition) {
679 Token operator = condition.operator; 681 Token operator = condition.operator;
680 if (operator != null && 682 if (operator != null &&
681 (operator.type == TokenType.AMPERSAND_AMPERSAND || 683 (operator.type == TokenType.AMPERSAND_AMPERSAND ||
682 operator.type == TokenType.BAR_BAR)) { 684 operator.type == TokenType.BAR_BAR)) {
683 _checkForPossibleNullCondition(condition.leftOperand); 685 _checkForPossibleNullCondition(condition.leftOperand);
684 _checkForPossibleNullCondition(condition.rightOperand); 686 _checkForPossibleNullCondition(condition.rightOperand);
685 } 687 }
686 } 688 }
687 689
688 /** 690 /**
691 * Produce a hint if the operand of the given prefix [condition] could
692 * have a value of `null`.
693 */
694 void _checkForPossibleNullConditionInPrefixExpression(
695 PrefixExpression condition) {
696 if (condition.operator?.type == TokenType.BANG) {
697 _checkForPossibleNullCondition(condition.operand);
698 }
699 }
700
701 /**
689 * Produce a hint if the given [condition] could have a value of `null`. 702 * Produce a hint if the given [condition] could have a value of `null`.
690 */ 703 */
691 void _checkForPossibleNullConditionInSimpleExpression(Expression condition) { 704 void _checkForPossibleNullConditionInSimpleExpression(Expression condition) {
692 if (condition is MethodInvocation) { 705 if (condition is MethodInvocation) {
693 Token operator = condition.operator; 706 Token operator = condition.operator;
694 if (operator != null && operator.type == TokenType.QUESTION_PERIOD) { 707 if (operator != null && operator.type == TokenType.QUESTION_PERIOD) {
695 _errorReporter.reportErrorForNode( 708 _errorReporter.reportErrorForNode(
696 HintCode.NULL_AWARE_IN_CONDITION, condition); 709 HintCode.NULL_AWARE_IN_CONDITION, condition);
697 } 710 }
698 } else if (condition is PropertyAccess) { 711 } else if (condition is PropertyAccess) {
(...skipping 15352 matching lines...) Expand 10 before | Expand all | Expand 10 after
16051 nonFields.add(node); 16064 nonFields.add(node);
16052 return null; 16065 return null;
16053 } 16066 }
16054 16067
16055 @override 16068 @override
16056 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 16069 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
16057 16070
16058 @override 16071 @override
16059 Object visitWithClause(WithClause node) => null; 16072 Object visitWithClause(WithClause node) => null;
16060 } 16073 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698