OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Properties that result from Strong Mode analysis on an AST. | 5 /// Properties that result from Strong Mode analysis on an AST. |
6 /// | 6 /// |
7 /// These properties are not public, but provided by use of back-ends such as | 7 /// These properties are not public, but provided by use of back-ends such as |
8 /// Dart Dev Compiler. | 8 /// Dart Dev Compiler. |
9 | 9 |
10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
11 import 'package:analyzer/dart/element/type.dart'; | 11 import 'package:analyzer/dart/element/type.dart'; |
12 | 12 |
| 13 const String _implicitAssignmentCast = '_implicitAssignmentCast'; |
13 const String _implicitCast = '_implicitCast'; | 14 const String _implicitCast = '_implicitCast'; |
14 const String _hasImplicitCasts = '_hasImplicitCasts'; | 15 const String _hasImplicitCasts = '_hasImplicitCasts'; |
15 const String _isDynamicInvoke = '_isDynamicInvoke'; | 16 const String _isDynamicInvoke = '_isDynamicInvoke'; |
16 | 17 |
17 /// True if this compilation unit has any implicit casts, otherwise false. | 18 /// True if this compilation unit has any implicit casts, otherwise false. |
18 /// | 19 /// |
19 /// See also [getImplicitCast]. | 20 /// See also [getImplicitCast]. |
20 bool hasImplicitCasts(CompilationUnit node) { | 21 bool hasImplicitCasts(CompilationUnit node) { |
21 return node.getProperty/*<bool>*/(_hasImplicitCasts) ?? false; | 22 return node.getProperty/*<bool>*/(_hasImplicitCasts) ?? false; |
22 } | 23 } |
23 | 24 |
24 /// Sets [hasImplicitCasts] property for this compilation unit. | 25 /// Sets [hasImplicitCasts] property for this compilation unit. |
25 void setHasImplicitCasts(CompilationUnit node, bool value) { | 26 void setHasImplicitCasts(CompilationUnit node, bool value) { |
26 node.setProperty(_hasImplicitCasts, value == true ? true : null); | 27 node.setProperty(_hasImplicitCasts, value == true ? true : null); |
27 } | 28 } |
28 | 29 |
29 /// If this expression has an implicit cast, returns the type it is coerced to, | 30 /// If this expression has an implicit cast, returns the type it is coerced to, |
30 /// otherwise returns null. | 31 /// otherwise returns null. |
31 DartType getImplicitCast(Expression node) { | 32 DartType getImplicitCast(Expression node) { |
32 return node.getProperty/*<DartType>*/(_implicitCast); | 33 return node.getProperty/*<DartType>*/(_implicitCast); |
33 } | 34 } |
34 | 35 |
35 /// Sets the result of [getImplicitCast] for this node. | 36 /// Sets the result of [getImplicitCast] for this node. |
36 void setImplicitCast(Expression node, DartType type) { | 37 void setImplicitCast(Expression node, DartType type) { |
37 node.setProperty(_implicitCast, type); | 38 node.setProperty(_implicitCast, type); |
38 } | 39 } |
39 | 40 |
| 41 /// If this op-assign has an implicit cast on the assignment, returns the type |
| 42 /// it is coerced to, otherwise returns null. |
| 43 DartType getImplicitAssignmentCast(Expression node) { |
| 44 return node.getProperty/*<DartType>*/(_implicitAssignmentCast); |
| 45 } |
| 46 |
| 47 /// Sets the result of [getImplicitAssignmentCast] for this node. |
| 48 void setImplicitAssignmentCast(Expression node, DartType type) { |
| 49 node.setProperty(_implicitAssignmentCast, type); |
| 50 } |
| 51 |
40 /// True if this node is a dynamic operation that requires dispatch and/or | 52 /// True if this node is a dynamic operation that requires dispatch and/or |
41 /// checking at runtime. | 53 /// checking at runtime. |
42 bool isDynamicInvoke(Expression node) { | 54 bool isDynamicInvoke(Expression node) { |
43 return node.getProperty/*<bool>*/(_isDynamicInvoke) ?? false; | 55 return node.getProperty/*<bool>*/(_isDynamicInvoke) ?? false; |
44 } | 56 } |
45 | 57 |
46 /// Sets [isDynamicInvoke] property for this expression | 58 /// Sets [isDynamicInvoke] property for this expression |
47 void setIsDynamicInvoke(Expression node, bool value) { | 59 void setIsDynamicInvoke(Expression node, bool value) { |
48 node.setProperty(_isDynamicInvoke, value == true ? true : null); | 60 node.setProperty(_isDynamicInvoke, value == true ? true : null); |
49 } | 61 } |
OLD | NEW |