| 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 /// Types needed to implement "strong" checking in the Dart analyzer. This is | 5 /// Types needed to implement "strong" checking in the Dart analyzer. This is |
| 6 /// intended to be used by `analyzer_cli` and `analysis_server` packages. | 6 /// intended to be used by `analyzer_cli` and `analysis_server` packages. |
| 7 library dev_compiler.strong_mode; | 7 library dev_compiler.strong_mode; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show | 10 show |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 final bool onlyInferConstsAndFinalFields; | 101 final bool onlyInferConstsAndFinalFields; |
| 102 static const onlyInferConstAndFinalFieldsDefault = false; | 102 static const onlyInferConstAndFinalFieldsDefault = false; |
| 103 | 103 |
| 104 /// Whether to infer types downwards from local context | 104 /// Whether to infer types downwards from local context |
| 105 final bool inferDownwards; | 105 final bool inferDownwards; |
| 106 static const inferDownwardsDefault = true; | 106 static const inferDownwardsDefault = true; |
| 107 | 107 |
| 108 /// Whether to inject casts between Dart assignable types. | 108 /// Whether to inject casts between Dart assignable types. |
| 109 final bool relaxedCasts; | 109 final bool relaxedCasts; |
| 110 | 110 |
| 111 /// A list of non-nullable type names (e.g., 'int') | |
| 112 final List<String> nonnullableTypes; | |
| 113 static const List<String> NONNULLABLE_TYPES = const <String>[]; | |
| 114 | |
| 115 /// Whether to include hints about dynamic invokes and runtime checks. | 111 /// Whether to include hints about dynamic invokes and runtime checks. |
| 116 // TODO(jmesserly): this option is not used yet by DDC server mode or batch | 112 // TODO(jmesserly): this option is not used yet by DDC server mode or batch |
| 117 // compile to JS. | 113 // compile to JS. |
| 118 final bool hints; | 114 final bool hints; |
| 119 | 115 |
| 120 const StrongModeOptions( | 116 const StrongModeOptions( |
| 121 {this.hints: false, | 117 {this.hints: false, |
| 122 this.inferTransitively: inferTransitivelyDefault, | 118 this.inferTransitively: inferTransitivelyDefault, |
| 123 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, | 119 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, |
| 124 this.inferDownwards: inferDownwardsDefault, | 120 this.inferDownwards: inferDownwardsDefault, |
| 125 this.relaxedCasts: true, | 121 this.relaxedCasts: true}); |
| 126 this.nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}); | |
| 127 | 122 |
| 128 StrongModeOptions.fromArguments(ArgResults args, {String prefix: ''}) | 123 StrongModeOptions.fromArguments(ArgResults args, {String prefix: ''}) |
| 129 : relaxedCasts = args[prefix + 'relaxed-casts'], | 124 : relaxedCasts = args[prefix + 'relaxed-casts'], |
| 130 inferDownwards = args[prefix + 'infer-downwards'], | 125 inferDownwards = args[prefix + 'infer-downwards'], |
| 131 inferTransitively = args[prefix + 'infer-transitively'], | 126 inferTransitively = args[prefix + 'infer-transitively'], |
| 132 onlyInferConstsAndFinalFields = args[prefix + 'infer-only-finals'], | 127 onlyInferConstsAndFinalFields = args[prefix + 'infer-only-finals'], |
| 133 nonnullableTypes = _optionsToList(args[prefix + 'nonnullable'], | |
| 134 defaultValue: StrongModeOptions.NONNULLABLE_TYPES), | |
| 135 hints = args[prefix + 'hints']; | 128 hints = args[prefix + 'hints']; |
| 136 | 129 |
| 137 static ArgParser addArguments(ArgParser parser, | 130 static ArgParser addArguments(ArgParser parser, |
| 138 {String prefix: '', bool hide: false}) { | 131 {String prefix: '', bool hide: false}) { |
| 139 return parser | 132 return parser |
| 140 ..addFlag(prefix + 'hints', | 133 ..addFlag(prefix + 'hints', |
| 141 help: 'Display hints about dynamic casts and dispatch operations', | 134 help: 'Display hints about dynamic casts and dispatch operations', |
| 142 defaultsTo: false, | 135 defaultsTo: false, |
| 143 hide: hide) | 136 hide: hide) |
| 144 ..addFlag(prefix + 'relaxed-casts', | 137 ..addFlag(prefix + 'relaxed-casts', |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 defaultsTo: onlyInferConstAndFinalFieldsDefault, | 156 defaultsTo: onlyInferConstAndFinalFieldsDefault, |
| 164 hide: hide); | 157 hide: hide); |
| 165 } | 158 } |
| 166 | 159 |
| 167 bool operator ==(Object other) { | 160 bool operator ==(Object other) { |
| 168 if (other is! StrongModeOptions) return false; | 161 if (other is! StrongModeOptions) return false; |
| 169 StrongModeOptions s = other; | 162 StrongModeOptions s = other; |
| 170 return inferTransitively == s.inferTransitively && | 163 return inferTransitively == s.inferTransitively && |
| 171 onlyInferConstsAndFinalFields == s.onlyInferConstsAndFinalFields && | 164 onlyInferConstsAndFinalFields == s.onlyInferConstsAndFinalFields && |
| 172 inferDownwards == s.inferDownwards && | 165 inferDownwards == s.inferDownwards && |
| 173 relaxedCasts == s.relaxedCasts && | 166 relaxedCasts == s.relaxedCasts; |
| 174 nonnullableTypes.length == s.nonnullableTypes.length && | |
| 175 new Set.from(nonnullableTypes).containsAll(s.nonnullableTypes); | |
| 176 } | 167 } |
| 177 } | 168 } |
| 178 | |
| 179 List<String> _optionsToList(String option, | |
| 180 {List<String> defaultValue: const <String>[]}) { | |
| 181 if (option == null) { | |
| 182 return defaultValue; | |
| 183 } else if (option.isEmpty) { | |
| 184 return <String>[]; | |
| 185 } else { | |
| 186 return option.split(','); | |
| 187 } | |
| 188 } | |
| OLD | NEW |