| 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. | 5 /// Types needed to implement "strong" checking in the Dart analyzer. |
| 6 /// This is intended to be used by analyzer_cli and analysis_server packages. | 6 /// This is 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 AnalysisContextImpl, AnalysisErrorInfo, AnalysisErrorInfoImpl; | 10 show AnalysisContextImpl, AnalysisErrorInfo, AnalysisErrorInfoImpl; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void onError(AnalysisError error) { | 65 void onError(AnalysisError error) { |
| 66 // Unless DDC hints are requested, filter them out. | 66 // Unless DDC hints are requested, filter them out. |
| 67 var HINT = ErrorSeverity.INFO.ordinal; | 67 var HINT = ErrorSeverity.INFO.ordinal; |
| 68 if (hints || error.errorCode.errorSeverity.ordinal > HINT) { | 68 if (hints || error.errorCode.errorSeverity.ordinal > HINT) { |
| 69 errors.add(error); | 69 errors.add(error); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 class StrongModeOptions { | 74 class StrongModeOptions { |
| 75 | |
| 76 /// Whether to infer return types and field types from overridden members. | 75 /// Whether to infer return types and field types from overridden members. |
| 77 final bool inferFromOverrides; | 76 final bool inferFromOverrides; |
| 78 static const inferFromOverridesDefault = true; | 77 static const inferFromOverridesDefault = true; |
| 79 | 78 |
| 80 /// Whether to infer types for consts and fields by looking at initializers on | 79 /// Whether to infer types for consts and fields by looking at initializers on |
| 81 /// the RHS. For example, in a constant declaration like: | 80 /// the RHS. For example, in a constant declaration like: |
| 82 /// | 81 /// |
| 83 /// const A = B; | 82 /// const A = B; |
| 84 /// | 83 /// |
| 85 /// We can infer the type of `A` based on the type of `B`. | 84 /// We can infer the type of `A` based on the type of `B`. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 108 | 107 |
| 109 /// A list of non-nullable type names (e.g., 'int') | 108 /// A list of non-nullable type names (e.g., 'int') |
| 110 final List<String> nonnullableTypes; | 109 final List<String> nonnullableTypes; |
| 111 static const List<String> NONNULLABLE_TYPES = const <String>[]; | 110 static const List<String> NONNULLABLE_TYPES = const <String>[]; |
| 112 | 111 |
| 113 /// Whether to include hints about dynamic invokes and runtime checks. | 112 /// Whether to include hints about dynamic invokes and runtime checks. |
| 114 // TODO(jmesserly): this option is not used yet by DDC server mode or batch | 113 // TODO(jmesserly): this option is not used yet by DDC server mode or batch |
| 115 // compile to JS. | 114 // compile to JS. |
| 116 final bool hints; | 115 final bool hints; |
| 117 | 116 |
| 118 const StrongModeOptions({this.hints: false, | 117 const StrongModeOptions( |
| 118 {this.hints: false, |
| 119 this.inferFromOverrides: inferFromOverridesDefault, | 119 this.inferFromOverrides: inferFromOverridesDefault, |
| 120 this.inferTransitively: inferTransitivelyDefault, | 120 this.inferTransitively: inferTransitivelyDefault, |
| 121 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, | 121 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, |
| 122 this.inferDownwards: inferDownwardsDefault, this.relaxedCasts: true, | 122 this.inferDownwards: inferDownwardsDefault, |
| 123 this.relaxedCasts: true, |
| 123 this.nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}); | 124 this.nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}); |
| 124 | 125 |
| 125 StrongModeOptions.fromArguments(ArgResults args, {String prefix: ''}) | 126 StrongModeOptions.fromArguments(ArgResults args, {String prefix: ''}) |
| 126 : relaxedCasts = args[prefix + 'relaxed-casts'], | 127 : relaxedCasts = args[prefix + 'relaxed-casts'], |
| 127 inferDownwards = args[prefix + 'infer-downwards'], | 128 inferDownwards = args[prefix + 'infer-downwards'], |
| 128 inferFromOverrides = args[prefix + 'infer-from-overrides'], | 129 inferFromOverrides = args[prefix + 'infer-from-overrides'], |
| 129 inferTransitively = args[prefix + 'infer-transitively'], | 130 inferTransitively = args[prefix + 'infer-transitively'], |
| 130 onlyInferConstsAndFinalFields = args[prefix + 'infer-only-finals'], | 131 onlyInferConstsAndFinalFields = args[prefix + 'infer-only-finals'], |
| 131 nonnullableTypes = _optionsToList(args[prefix + 'nonnullable'], | 132 nonnullableTypes = _optionsToList(args[prefix + 'nonnullable'], |
| 132 defaultValue: StrongModeOptions.NONNULLABLE_TYPES), | 133 defaultValue: StrongModeOptions.NONNULLABLE_TYPES), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 147 abbr: prefix == '' ? 'n' : null, | 148 abbr: prefix == '' ? 'n' : null, |
| 148 help: 'Comma separated string of non-nullable types', | 149 help: 'Comma separated string of non-nullable types', |
| 149 defaultsTo: null, | 150 defaultsTo: null, |
| 150 hide: hide) | 151 hide: hide) |
| 151 ..addFlag(prefix + 'infer-downwards', | 152 ..addFlag(prefix + 'infer-downwards', |
| 152 help: 'Infer types downwards from local context', | 153 help: 'Infer types downwards from local context', |
| 153 defaultsTo: inferDownwardsDefault, | 154 defaultsTo: inferDownwardsDefault, |
| 154 hide: hide) | 155 hide: hide) |
| 155 ..addFlag(prefix + 'infer-from-overrides', | 156 ..addFlag(prefix + 'infer-from-overrides', |
| 156 help: 'Infer unspecified types of fields and return types from\n' | 157 help: 'Infer unspecified types of fields and return types from\n' |
| 157 'definitions in supertypes', | 158 'definitions in supertypes', |
| 158 defaultsTo: inferFromOverridesDefault, | 159 defaultsTo: inferFromOverridesDefault, |
| 159 hide: hide) | 160 hide: hide) |
| 160 ..addFlag(prefix + 'infer-transitively', | 161 ..addFlag(prefix + 'infer-transitively', |
| 161 help: 'Infer consts/fields from definitions in other libraries', | 162 help: 'Infer consts/fields from definitions in other libraries', |
| 162 defaultsTo: inferTransitivelyDefault, | 163 defaultsTo: inferTransitivelyDefault, |
| 163 hide: hide) | 164 hide: hide) |
| 164 ..addFlag(prefix + 'infer-only-finals', | 165 ..addFlag(prefix + 'infer-only-finals', |
| 165 help: 'Do not infer non-const or non-final fields', | 166 help: 'Do not infer non-const or non-final fields', |
| 166 defaultsTo: onlyInferConstAndFinalFieldsDefault, | 167 defaultsTo: onlyInferConstAndFinalFieldsDefault, |
| 167 hide: hide); | 168 hide: hide); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 183 List<String> _optionsToList(String option, | 184 List<String> _optionsToList(String option, |
| 184 {List<String> defaultValue: const <String>[]}) { | 185 {List<String> defaultValue: const <String>[]}) { |
| 185 if (option == null) { | 186 if (option == null) { |
| 186 return defaultValue; | 187 return defaultValue; |
| 187 } else if (option.isEmpty) { | 188 } else if (option.isEmpty) { |
| 188 return <String>[]; | 189 return <String>[]; |
| 189 } else { | 190 } else { |
| 190 return option.split(','); | 191 return option.split(','); |
| 191 } | 192 } |
| 192 } | 193 } |
| OLD | NEW |