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

Side by Side Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1445363002: Embedded options discovery (#24943). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.options; 5 library analyzer.src.task.options;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/plugin/options.dart'; 8 import 'package:analyzer/plugin/options.dart';
9 import 'package:analyzer/source/analysis_options_provider.dart'; 9 import 'package:analyzer/source/analysis_options_provider.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 List<int> lineStarts = StringUtilities.computeLineStarts(content); 220 List<int> lineStarts = StringUtilities.computeLineStarts(content);
221 return new LineInfo(lineStarts); 221 return new LineInfo(lineStarts);
222 } 222 }
223 223
224 /// Create a task based on the given [target] in the given [context]. 224 /// Create a task based on the given [target] in the given [context].
225 static GenerateOptionsErrorsTask createTask( 225 static GenerateOptionsErrorsTask createTask(
226 AnalysisContext context, AnalysisTarget target) => 226 AnalysisContext context, AnalysisTarget target) =>
227 new GenerateOptionsErrorsTask(context, target); 227 new GenerateOptionsErrorsTask(context, target);
228 } 228 }
229 229
230 /// Validates `analyzer` strong-mode value configuration options.
231 class StrongModeOptionValueValidator extends OptionsValidator {
232 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder();
233
234 @override
235 void validate(ErrorReporter reporter, Map<String, YamlNode> options) {
236 var analyzer = options[AnalyzerOptions.analyzer];
237 if (analyzer is! YamlMap) {
238 return;
239 }
240
241 var v = analyzer.nodes[AnalyzerOptions.strong_mode];
242 if (v is YamlScalar) {
243 var value = toLowerCase(v.value);
244 if (!AnalyzerOptions.trueOrFalse.contains(value)) {
245 trueOrFalseBuilder.reportError(
246 reporter, AnalyzerOptions.strong_mode, v);
247 }
248 }
249 }
250 }
251
252 /// Validates `analyzer` language configuration options. 230 /// Validates `analyzer` language configuration options.
253 class LanguageOptionValidator extends OptionsValidator { 231 class LanguageOptionValidator extends OptionsValidator {
254 ErrorBuilder builder = new ErrorBuilder(AnalyzerOptions.languageOptions); 232 ErrorBuilder builder = new ErrorBuilder(AnalyzerOptions.languageOptions);
255 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder(); 233 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder();
256 234
257 @override 235 @override
258 void validate(ErrorReporter reporter, Map<String, YamlNode> options) { 236 void validate(ErrorReporter reporter, Map<String, YamlNode> options) {
259 var analyzer = options[AnalyzerOptions.analyzer]; 237 var analyzer = options[AnalyzerOptions.analyzer];
260 if (analyzer is! YamlMap) { 238 if (analyzer is! YamlMap) {
261 return; 239 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 284 }
307 285
308 List<AnalysisError> validate(Map<String, YamlNode> options) { 286 List<AnalysisError> validate(Map<String, YamlNode> options) {
309 RecordingErrorListener recorder = new RecordingErrorListener(); 287 RecordingErrorListener recorder = new RecordingErrorListener();
310 ErrorReporter reporter = new ErrorReporter(recorder, source); 288 ErrorReporter reporter = new ErrorReporter(recorder, source);
311 _validators.forEach((OptionsValidator v) => v.validate(reporter, options)); 289 _validators.forEach((OptionsValidator v) => v.validate(reporter, options));
312 return recorder.errors; 290 return recorder.errors;
313 } 291 }
314 } 292 }
315 293
294 /// Validates `analyzer` strong-mode value configuration options.
295 class StrongModeOptionValueValidator extends OptionsValidator {
296 ErrorBuilder trueOrFalseBuilder = new TrueOrFalseValueErrorBuilder();
297
298 @override
299 void validate(ErrorReporter reporter, Map<String, YamlNode> options) {
300 var analyzer = options[AnalyzerOptions.analyzer];
301 if (analyzer is! YamlMap) {
302 return;
303 }
304
305 var v = analyzer.nodes[AnalyzerOptions.strong_mode];
306 if (v is YamlScalar) {
307 var value = toLowerCase(v.value);
308 if (!AnalyzerOptions.trueOrFalse.contains(value)) {
309 trueOrFalseBuilder.reportError(
310 reporter, AnalyzerOptions.strong_mode, v);
311 }
312 }
313 }
314 }
315
316 /// Validates `analyzer` top-level options. 316 /// Validates `analyzer` top-level options.
317 class TopLevelAnalyzerOptionsValidator extends TopLevelOptionValidator { 317 class TopLevelAnalyzerOptionsValidator extends TopLevelOptionValidator {
318 TopLevelAnalyzerOptionsValidator() 318 TopLevelAnalyzerOptionsValidator()
319 : super(AnalyzerOptions.analyzer, AnalyzerOptions.topLevel); 319 : super(AnalyzerOptions.analyzer, AnalyzerOptions.topLevel);
320 } 320 }
321 321
322 /// Validates top-level options. For example, 322 /// Validates top-level options. For example,
323 /// plugin: 323 /// plugin:
324 /// top-level-option: true 324 /// top-level-option: true
325 class TopLevelOptionValidator extends OptionsValidator { 325 class TopLevelOptionValidator extends OptionsValidator {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE; 365 AnalysisOptionsWarningCode.UNSUPPORTED_VALUE;
366 } 366 }
367 367
368 class _OptionsProcessor { 368 class _OptionsProcessor {
369 void configure(AnalysisContext context, Map<String, YamlNode> options) { 369 void configure(AnalysisContext context, Map<String, YamlNode> options) {
370 if (options == null) { 370 if (options == null) {
371 return; 371 return;
372 } 372 }
373 373
374 var analyzer = options[AnalyzerOptions.analyzer]; 374 var analyzer = options[AnalyzerOptions.analyzer];
375 if (analyzer is! YamlMap) { 375 if (analyzer is! Map) {
376 return; 376 return;
377 } 377 }
378 378
379 // Set strong mode (default is false). 379 // Set strong mode (default is false).
380 var strongMode = analyzer[AnalyzerOptions.strong_mode]; 380 var strongMode = analyzer[AnalyzerOptions.strong_mode];
381 setStrongMode(context, strongMode); 381 setStrongMode(context, strongMode);
382 382
383 // Set filters. 383 // Set filters.
384 var filters = analyzer[AnalyzerOptions.errors]; 384 var filters = analyzer[AnalyzerOptions.errors];
385 setFilters(context, filters); 385 setFilters(context, filters);
(...skipping 16 matching lines...) Expand all
402 // Case-insensitive. 402 // Case-insensitive.
403 String code = toUpperCase(k.value); 403 String code = toUpperCase(k.value);
404 filters.add((AnalysisError error) => error.errorCode.name == code); 404 filters.add((AnalysisError error) => error.errorCode.name == code);
405 } 405 }
406 } 406 }
407 }); 407 });
408 } 408 }
409 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters); 409 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, filters);
410 } 410 }
411 411
412 void setLanguageOption(
413 AnalysisContext context, Object feature, Object value) {
414 if (feature == AnalyzerOptions.enableSuperMixins) {
415 if (isTrue(value)) {
416 AnalysisOptionsImpl options =
417 new AnalysisOptionsImpl.from(context.analysisOptions);
418 options.enableSuperMixins = true;
419 context.analysisOptions = options;
420 }
421 }
422 if (feature == AnalyzerOptions.enableGenericMethods) {
423 if (isTrue(value)) {
424 AnalysisOptionsImpl options =
425 new AnalysisOptionsImpl.from(context.analysisOptions);
426 options.enableGenericMethods = true;
427 context.analysisOptions = options;
428 }
429 }
430 }
431
412 void setLanguageOptions(AnalysisContext context, Object configs) { 432 void setLanguageOptions(AnalysisContext context, Object configs) {
413 if (configs is YamlMap) { 433 if (configs is YamlMap) {
414 configs.nodes.forEach((k, v) { 434 configs.nodes.forEach((k, v) {
415 String feature;
416 if (k is YamlScalar && v is YamlScalar) { 435 if (k is YamlScalar && v is YamlScalar) {
417 feature = k.value?.toString(); 436 String feature = k.value?.toString();
418 if (feature == AnalyzerOptions.enableSuperMixins) { 437 setLanguageOption(context, feature, v.value);
419 if (isTrue(v.value)) {
420 AnalysisOptionsImpl options =
421 new AnalysisOptionsImpl.from(context.analysisOptions);
422 options.enableSuperMixins = true;
423 context.analysisOptions = options;
424 }
425 }
426 if (feature == AnalyzerOptions.enableGenericMethods) {
427 if (isTrue(v.value)) {
428 AnalysisOptionsImpl options =
429 new AnalysisOptionsImpl.from(context.analysisOptions);
430 options.enableGenericMethods = true;
431 context.analysisOptions = options;
432 }
433 }
434 } 438 }
435 }); 439 });
440 } else if (configs is Map) {
441 configs.forEach((k, v) => setLanguageOption(context, k, v));
436 } 442 }
437 } 443 }
438 444
439 void setStrongMode(AnalysisContext context, Object strongMode) { 445 void setStrongMode(AnalysisContext context, Object strongMode) {
440 bool strong = strongMode is bool ? strongMode : false; 446 bool strong = strongMode is bool ? strongMode : false;
441 if (context.analysisOptions.strongMode != strong) { 447 if (context.analysisOptions.strongMode != strong) {
442 AnalysisOptionsImpl options = 448 AnalysisOptionsImpl options =
443 new AnalysisOptionsImpl.from(context.analysisOptions); 449 new AnalysisOptionsImpl.from(context.analysisOptions);
444 options.strongMode = strong; 450 options.strongMode = strong;
445 context.analysisOptions = options; 451 context.analysisOptions = options;
446 } 452 }
447 } 453 }
448 } 454 }
OLDNEW
« 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