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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 1933763002: Use null-aware operators to clean up the code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Additional clean-up Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.checker; 7 library analyzer.src.task.strong.checker;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 var staticInfo = 318 var staticInfo =
319 new InvalidParameterDeclaration(rules, node, fieldType); 319 new InvalidParameterDeclaration(rules, node, fieldType);
320 _recordMessage(staticInfo); 320 _recordMessage(staticInfo);
321 } 321 }
322 } 322 }
323 node.visitChildren(this); 323 node.visitChildren(this);
324 } 324 }
325 325
326 @override 326 @override
327 void visitForEachStatement(ForEachStatement node) { 327 void visitForEachStatement(ForEachStatement node) {
328 var loopVariable = node.identifier != null 328 var loopVariable = node.identifier ?? node.loopVariable?.identifier;
329 ? node.identifier
330 : node.loopVariable?.identifier;
331 329
332 // Safely handle malformed statements. 330 // Safely handle malformed statements.
333 if (loopVariable != null) { 331 if (loopVariable != null) {
334 // Find the element type of the sequence. 332 // Find the element type of the sequence.
335 var sequenceInterface = node.awaitKeyword != null 333 var sequenceInterface = node.awaitKeyword != null
336 ? typeProvider.streamType 334 ? typeProvider.streamType
337 : typeProvider.iterableType; 335 : typeProvider.iterableType;
338 var iterableType = _getStaticType(node.iterable); 336 var iterableType = _getStaticType(node.iterable);
339 var elementType = 337 var elementType =
340 rules.mostSpecificTypeArgument(iterableType, sequenceInterface); 338 rules.mostSpecificTypeArgument(iterableType, sequenceInterface);
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 if (node != null) { 1125 if (node != null) {
1128 _checkIndividualOverridesFromClass(node, interfaceType, seen, false); 1126 _checkIndividualOverridesFromClass(node, interfaceType, seen, false);
1129 } else { 1127 } else {
1130 _checkIndividualOverridesFromType( 1128 _checkIndividualOverridesFromType(
1131 type, interfaceType, errorLocation, seen, false); 1129 type, interfaceType, errorLocation, seen, false);
1132 } 1130 }
1133 } 1131 }
1134 1132
1135 // Check overrides from its mixins 1133 // Check overrides from its mixins
1136 for (int i = 0; i < type.mixins.length; i++) { 1134 for (int i = 0; i < type.mixins.length; i++) {
1137 var loc = 1135 var loc = errorLocation ?? node.withClause.mixinTypes[i];
1138 errorLocation != null ? errorLocation : node.withClause.mixinTypes[i];
1139 for (var interfaceType in interfaces) { 1136 for (var interfaceType in interfaces) {
1140 // We copy [seen] so we can report separately if more than one mixin or 1137 // We copy [seen] so we can report separately if more than one mixin or
1141 // the base class have an invalid override. 1138 // the base class have an invalid override.
1142 _checkIndividualOverridesFromType( 1139 _checkIndividualOverridesFromType(
1143 type.mixins[i], interfaceType, loc, new Set.from(seen), false); 1140 type.mixins[i], interfaceType, loc, new Set.from(seen), false);
1144 } 1141 }
1145 } 1142 }
1146 1143
1147 // Check overrides from its superclasses 1144 // Check overrides from its superclasses
1148 if (includeParents) { 1145 if (includeParents) {
1149 var parent = type.superclass; 1146 var parent = type.superclass;
1150 if (parent.isObject) return; 1147 if (parent.isObject) {
1151 var loc = errorLocation != null ? errorLocation : node.extendsClause; 1148 return;
1149 }
1150 var loc = errorLocation ?? node.extendsClause;
1152 // No need to copy [seen] here because we made copies above when reporting 1151 // No need to copy [seen] here because we made copies above when reporting
1153 // errors on mixins. 1152 // errors on mixins.
1154 _checkInterfacesOverrides(parent, interfaces, seen, 1153 _checkInterfacesOverrides(parent, interfaces, seen,
1155 visited: visited, includeParents: true, errorLocation: loc); 1154 visited: visited, includeParents: true, errorLocation: loc);
1156 } 1155 }
1157 } 1156 }
1158 1157
1159 /// Check overrides from mixin applications themselves. For example, in: 1158 /// Check overrides from mixin applications themselves. For example, in:
1160 /// 1159 ///
1161 /// A extends B with E, F 1160 /// A extends B with E, F
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 } while (!current.isObject && !visited.contains(current)); 1292 } while (!current.isObject && !visited.contains(current));
1294 } 1293 }
1295 1294
1296 void _recordMessage(StaticInfo info) { 1295 void _recordMessage(StaticInfo info) {
1297 if (info == null) return; 1296 if (info == null) return;
1298 var error = info.toAnalysisError(); 1297 var error = info.toAnalysisError();
1299 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true; 1298 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) _failure = true;
1300 _reporter.onError(error); 1299 _reporter.onError(error);
1301 } 1300 }
1302 } 1301 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/source_io.dart ('k') | pkg/analyzer/lib/src/task/strong/info.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698