Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1503353002: Embedded option processing fixes (#25115). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/options.dart
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index ee6823efffc25234ea54c70e1c31af27900f8593..ac03408177ce4104d411ac7a36b1942c48ec4e97 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -30,9 +30,9 @@ final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS =
final _OptionsProcessor _processor = new _OptionsProcessor();
/// Configure this [context] based on configuration details specified in
-/// the given [options].
+/// the given [options]. If [options] is `null`, default values are applied.
void configureContextOptions(
- AnalysisContext context, Map<String, YamlNode> options) =>
+ AnalysisContext context, Map<String, Object> options) =>
_processor.configure(context, options);
/// `analyzer` analysis options constants.
@@ -384,9 +384,13 @@ class TrueOrFalseValueErrorBuilder extends ErrorBuilder {
}
class _OptionsProcessor {
- void configure(AnalysisContext context, Map<String, YamlNode> options) {
+ static final Map<String, Object> defaults = {'analyzer': {}};
+
+ /// Configure [context] based on the given [options] (which can be `null`
+ /// to restore [defaults]).
+ void configure(AnalysisContext context, Map<String, Object> options) {
if (options == null) {
- return;
+ options = defaults;
}
var analyzer = options[AnalyzerOptions.analyzer];
@@ -407,19 +411,36 @@ class _OptionsProcessor {
setLanguageOptions(context, language);
}
+ ErrorFilter parseFilter(String code, Object enable) {
+ enable = toLowerCase(enable);
+ if (AnalyzerOptions.ignoreSynonyms.contains(enable)) {
+ // Case-insensitive.
+ code = toUpperCase(code);
+ return ((AnalysisError error) => error.errorCode.name == code);
+ }
+ }
+
void setFilters(AnalysisContext context, Object codes) {
List<ErrorFilter> filters = <ErrorFilter>[];
// If codes are enumerated, collect them as filters; else leave filters
// empty to overwrite previous value.
if (codes is YamlMap) {
String value;
+ // TODO(pq): stop traversing nodes and unify w/ standard map handling
codes.nodes.forEach((k, v) {
if (k is YamlScalar && v is YamlScalar) {
- value = toLowerCase(v.value);
- if (AnalyzerOptions.ignoreSynonyms.contains(value)) {
- // Case-insensitive.
- String code = toUpperCase(k.value);
- filters.add((AnalysisError error) => error.errorCode.name == code);
+ ErrorFilter filter = parseFilter(k.value, v.value);
+ if (filter != null) {
+ filters.add(filter);
+ }
+ }
+ });
+ } else if (codes is Map) {
+ codes.forEach((k, v) {
+ if (k is String) {
+ ErrorFilter filter = parseFilter(k, v);
+ if (filter != null) {
+ filters.add(filter);
}
}
});
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698