OLD | NEW |
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 library analyzer.src.task.strong_mode; | 5 library analyzer.src.task.strong_mode; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // | 256 // |
257 _inferType(classElement.supertype); | 257 _inferType(classElement.supertype); |
258 classElement.mixins.forEach(_inferType); | 258 classElement.mixins.forEach(_inferType); |
259 classElement.interfaces.forEach(_inferType); | 259 classElement.interfaces.forEach(_inferType); |
260 // | 260 // |
261 // Then infer the types for the members. | 261 // Then infer the types for the members. |
262 // | 262 // |
263 classElement.fields.forEach(_inferField); | 263 classElement.fields.forEach(_inferField); |
264 classElement.accessors.forEach(_inferExecutable); | 264 classElement.accessors.forEach(_inferExecutable); |
265 classElement.methods.forEach(_inferExecutable); | 265 classElement.methods.forEach(_inferExecutable); |
| 266 // |
| 267 // Infer initializing formal parameter types. This must happen after |
| 268 // field types are inferred. |
| 269 // |
| 270 classElement.constructors.forEach(_inferConstructorFieldFormals); |
266 classElement.hasBeenInferred = true; | 271 classElement.hasBeenInferred = true; |
267 } finally { | 272 } finally { |
268 elementsBeingInferred.remove(classElement); | 273 elementsBeingInferred.remove(classElement); |
269 } | 274 } |
270 } | 275 } |
271 } | 276 } |
272 | 277 |
273 /** | 278 /** |
274 * If the given [fieldElement] represents a non-synthetic instance field for | 279 * If the given [fieldElement] represents a non-synthetic instance field for |
275 * which no type was provided, infer the type of the field. | 280 * which no type was provided, infer the type of the field. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 return true; | 439 return true; |
435 } | 440 } |
436 | 441 |
437 /** | 442 /** |
438 * Return `true` if the list of [elements] contains only methods. | 443 * Return `true` if the list of [elements] contains only methods. |
439 */ | 444 */ |
440 bool _allSameElementKind( | 445 bool _allSameElementKind( |
441 ExecutableElement element, List<ExecutableElement> elements) { | 446 ExecutableElement element, List<ExecutableElement> elements) { |
442 return elements.every((e) => e.kind == element.kind); | 447 return elements.every((e) => e.kind == element.kind); |
443 } | 448 } |
| 449 |
| 450 void _inferConstructorFieldFormals(ConstructorElement element) { |
| 451 for (ParameterElement p in element.parameters) { |
| 452 if (p is FieldFormalParameterElement) { |
| 453 _inferFieldFormalParameter(p); |
| 454 } |
| 455 } |
| 456 } |
| 457 |
| 458 void _inferFieldFormalParameter(FieldFormalParameterElement element) { |
| 459 FieldElement field = element.field; |
| 460 if (field != null && element.hasImplicitType) { |
| 461 (element as FieldFormalParameterElementImpl).type = field.type; |
| 462 } |
| 463 } |
444 } | 464 } |
445 | 465 |
446 /** | 466 /** |
447 * A visitor that will gather all of the variables referenced within a given | 467 * A visitor that will gather all of the variables referenced within a given |
448 * AST structure. The collection can be restricted to contain only those | 468 * AST structure. The collection can be restricted to contain only those |
449 * variables that pass a specified filter. | 469 * variables that pass a specified filter. |
450 */ | 470 */ |
451 class VariableGatherer extends RecursiveAstVisitor { | 471 class VariableGatherer extends RecursiveAstVisitor { |
452 /** | 472 /** |
453 * The filter used to limit which variables are gathered, or `null` if no | 473 * The filter used to limit which variables are gathered, or `null` if no |
(...skipping 23 matching lines...) Expand all Loading... |
477 results.add(element); | 497 results.add(element); |
478 } | 498 } |
479 } | 499 } |
480 } | 500 } |
481 } | 501 } |
482 | 502 |
483 /** | 503 /** |
484 * A class of exception that is not used anywhere else. | 504 * A class of exception that is not used anywhere else. |
485 */ | 505 */ |
486 class _CycleException implements Exception {} | 506 class _CycleException implements Exception {} |
OLD | NEW |