Chromium Code Reviews| 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'; |
| 11 import 'package:analyzer/src/generated/resolver.dart' | 11 import 'package:analyzer/src/generated/resolver.dart' |
| 12 show TypeProvider, InheritanceManager; | 12 show TypeProvider, InheritanceManager; |
| 13 import 'package:analyzer/src/generated/type_system.dart'; | 13 import 'package:analyzer/src/generated/type_system.dart'; |
| 14 import 'package:analyzer/src/generated/utilities_dart.dart'; | 14 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Set the type of the sole parameter of the given [element] to the given [type] . | 17 * Set the type of the sole parameter of the given [element] to the given [type] . |
| 18 */ | 18 */ |
| 19 void setParameterType(PropertyAccessorElement element, DartType type) { | 19 void setParameterType(PropertyAccessorElement element, DartType type) { |
| 20 if (element is PropertyAccessorElementImpl) { | 20 if (element is PropertyAccessorElementImpl) { |
| 21 ParameterElement parameter = _getParameter(element); | 21 ParameterElement parameter = _getParameter(element); |
| 22 if (parameter is ParameterElementImpl) { | 22 if (parameter is ParameterElementImpl) { |
| 23 // | 23 // |
| 24 // Update the type of the parameter. | 24 // Update the type of the parameter. |
| 25 // | 25 // |
| 26 parameter.type = type; | 26 parameter.type = type; |
| 27 // | 27 // |
| 28 // Update the type of the setter to reflect the new parameter type. | 28 // Update the type of the setter to reflect the new parameter type. |
| 29 // | 29 // |
| 30 // TODO(jmesserly): why is this necessary? The function type should always | |
|
Brian Wilkerson
2015/11/13 18:56:16
Good question! I don't know. Does anything break i
Jennifer Messerly
2015/11/13 19:04:46
Yeah, I was planning to give it a shot right after
Brian Wilkerson
2015/11/13 20:17:14
Sounds good. Certainly not necessary before landin
| |
| 31 // delegate to the orginal element. | |
| 30 FunctionType functionType = element.type; | 32 FunctionType functionType = element.type; |
| 31 if (functionType is FunctionTypeImpl) { | 33 if (functionType is FunctionTypeImpl) { |
| 32 element.type = | 34 element.type = new FunctionTypeImpl(element); |
| 33 new FunctionTypeImpl(element, functionType.prunedTypedefs) | |
| 34 ..typeArguments = functionType.typeArguments; | |
| 35 } else { | 35 } else { |
| 36 assert(false); | 36 assert(false); |
| 37 } | 37 } |
| 38 } else { | 38 } else { |
| 39 assert(false); | 39 assert(false); |
| 40 } | 40 } |
| 41 } else { | 41 } else { |
| 42 throw new StateError('element is an instance of ${element.runtimeType}'); | 42 throw new StateError('element is an instance of ${element.runtimeType}'); |
| 43 assert(false); | 43 assert(false); |
|
Brian Wilkerson
2015/11/13 18:56:16
Also, why is there an assert after a throw? We can
Jennifer Messerly
2015/11/13 19:04:46
yeah--it's strange right? The asserts above seem s
Jennifer Messerly
2015/11/13 19:17:22
Thinking on this more, it seems like we just want
Brian Wilkerson
2015/11/13 20:17:14
The rationale we've used before is that we want th
| |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Set the return type of the given [element] to the given [type]. | 48 * Set the return type of the given [element] to the given [type]. |
| 49 */ | 49 */ |
| 50 void setReturnType(ExecutableElement element, DartType type) { | 50 void setReturnType(ExecutableElement element, DartType type) { |
| 51 if (element is ExecutableElementImpl) { | 51 if (element is ExecutableElementImpl) { |
| 52 // | 52 // |
| 53 // Update the return type of the element, which is stored in two places: | 53 // Update the return type of the element, which is stored in two places: |
| 54 // directly in the element and indirectly in the type of the element. | 54 // directly in the element and indirectly in the type of the element. |
| 55 // | 55 // |
| 56 // TODO(jmesserly): why is this necessary? The function type should always | |
| 57 // delegate to the orginal element. | |
| 56 element.returnType = type; | 58 element.returnType = type; |
| 57 FunctionType functionType = element.type; | 59 FunctionType functionType = element.type; |
| 58 if (functionType is FunctionTypeImpl) { | 60 if (functionType is FunctionTypeImpl) { |
| 59 element.type = new FunctionTypeImpl(element, functionType.prunedTypedefs) | 61 element.type = new FunctionTypeImpl(element); |
| 60 ..typeArguments = functionType.typeArguments; | |
| 61 } else { | 62 } else { |
| 62 assert(false); | 63 assert(false); |
| 63 } | 64 } |
| 64 } else { | 65 } else { |
| 65 assert(false); | 66 assert(false); |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 /** | 70 /** |
| 70 * Return the element for the single parameter of the given [setter], or `null` | 71 * Return the element for the single parameter of the given [setter], or `null` |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 results.add(element); | 500 results.add(element); |
| 500 } | 501 } |
| 501 } | 502 } |
| 502 } | 503 } |
| 503 } | 504 } |
| 504 | 505 |
| 505 /** | 506 /** |
| 506 * A class of exception that is not used anywhere else. | 507 * A class of exception that is not used anywhere else. |
| 507 */ | 508 */ |
| 508 class _CycleException implements Exception {} | 509 class _CycleException implements Exception {} |
| OLD | NEW |