Remove uses of configuration data

R=scheglov@google.com

Review URL: https://codereview.chromium.org/2522543007 .
This commit is contained in:
Brian Wilkerson 2016-11-22 11:26:08 -08:00
parent 2510646aaf
commit e63105555b
12 changed files with 125 additions and 66 deletions

View file

@ -46,8 +46,6 @@ import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/html.dart';
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer/src/task/options.dart'
show CONFIGURED_ERROR_PROCESSORS;
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/general.dart';
import 'package:analyzer/task/html.dart';
@ -1450,8 +1448,7 @@ class GetHandler {
});
},
(StringBuffer buffer) {
List<Linter> lints =
context.getConfigurationData(CONFIGURED_LINTS_KEY);
List<Linter> lints = context.analysisOptions.lintRules;
buffer.write('<p><b>Lints</b></p>');
if (lints.isEmpty) {
buffer.write('<p>none</p>');
@ -1464,7 +1461,7 @@ class GetHandler {
}
List<ErrorProcessor> errorProcessors =
context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
context.analysisOptions.errorProcessors;
int processorCount = errorProcessors?.length ?? 0;
buffer
.write('<p><b>Error Processor count</b>: $processorCount</p>');

View file

@ -20,8 +20,6 @@ import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/options.dart'
show CONFIGURED_ERROR_PROCESSORS;
import 'package:analyzer/src/util/glob.dart';
import 'package:linter/src/plugin/linter_plugin.dart';
import 'package:linter/src/rules/avoid_as.dart';
@ -1747,8 +1745,8 @@ abstract class ContextManagerTest {
.toList();
}
List<ErrorProcessor> get errorProcessors => callbacks.currentContext
.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
List<ErrorProcessor> get errorProcessors =>
callbacks.currentContext.analysisOptions.errorProcessors;
List<Linter> get lints => getLints(callbacks.currentContext);

View file

@ -8,8 +8,6 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/utilities_general.dart';
import 'package:analyzer/src/task/options.dart'
show CONFIGURED_ERROR_PROCESSORS;
import 'package:analyzer/src/task/options.dart';
import 'package:yaml/yaml.dart';
@ -98,8 +96,7 @@ class ErrorProcessor {
}
// Let the user configure how specific errors are processed.
List<ErrorProcessor> processors =
context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
List<ErrorProcessor> processors = context.analysisOptions.errorProcessors;
// Give strong mode a chance to upgrade it.
if (context.analysisOptions.strongMode) {

View file

@ -30,20 +30,12 @@ import 'package:analyzer/src/task/dart_work_manager.dart';
import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/incremental_element_builder.dart';
import 'package:analyzer/src/task/manager.dart';
import 'package:analyzer/src/task/model.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/general.dart';
import 'package:analyzer/task/html.dart';
import 'package:analyzer/task/model.dart';
import 'package:html/dom.dart' show Document;
/**
* The descriptor used to associate exclude patterns with an analysis context in
* configuration data.
*/
final ListResultDescriptor<String> CONTEXT_EXCLUDES =
new ListResultDescriptorImpl('CONTEXT_EXCLUDES', const <String>[]);
/**
* Type of callback functions used by PendingFuture. Functions of this type
* should perform a computation based on the data in [entry] and return it. If
@ -281,8 +273,11 @@ class AnalysisContextImpl implements InternalAnalysisContext {
options.generateImplicitErrors ||
this._options.generateSdkErrors != options.generateSdkErrors ||
this._options.dart2jsHint != options.dart2jsHint ||
_notEqual(this._options.errorProcessors, options.errorProcessors) ||
_notEqual(this._options.excludePatterns, options.excludePatterns) ||
(this._options.hint && !options.hint) ||
(this._options.lint && !options.lint) ||
_notEqual(this._options.lintRules, options.lintRules) ||
this._options.preserveComments != options.preserveComments ||
this._options.strongMode != options.strongMode ||
this._options.enableAssertInitializer !=
@ -322,11 +317,14 @@ class AnalysisContextImpl implements InternalAnalysisContext {
options.enableLazyAssignmentOperators;
this._options.enableSuperMixins = options.enableSuperMixins;
this._options.enableTiming = options.enableTiming;
this._options.errorProcessors = options.errorProcessors;
this._options.excludePatterns = options.excludePatterns;
this._options.hint = options.hint;
this._options.incremental = options.incremental;
this._options.incrementalApi = options.incrementalApi;
this._options.incrementalValidation = options.incrementalValidation;
this._options.lint = options.lint;
this._options.lintRules = options.lintRules;
this._options.preserveComments = options.preserveComments;
if (this._options.strongMode != options.strongMode) {
_typeSystem = null;
@ -847,6 +845,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
return getResult(target, COMPILATION_UNIT_ELEMENT);
}
@deprecated
@override
Object/*=V*/ getConfigurationData/*<V>*/(ResultDescriptor/*<V>*/ key) =>
(_configurationData[key] ?? key?.defaultValue) as Object/*=V*/;
@ -1307,6 +1306,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
}
@deprecated
@override
void setConfigurationData(ResultDescriptor key, Object data) {
_configurationData[key] = data;
@ -1696,6 +1696,19 @@ class AnalysisContextImpl implements InternalAnalysisContext {
AnalysisEngine.instance.logger.logInformation(message);
}
bool _notEqual/*<T>*/(List/*<T>*/ first, List/*<T>*/ second) {
int length = first.length;
if (length != second.length) {
return true;
}
for (int i = 0; i < length; i++) {
if (first[i] != second[i]) {
return true;
}
}
return false;
}
/**
* Notify all of the analysis listeners that the errors associated with the
* given [source] has been updated to the given [errors].

View file

@ -14,6 +14,7 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/plugin/resolver_provider.dart';
import 'package:analyzer/source/error_processor.dart';
import 'package:analyzer/src/cancelable_future.dart';
import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator;
import 'package:analyzer/src/context/cache.dart';
@ -26,6 +27,7 @@ import 'package:analyzer/src/generated/utilities_general.dart';
import 'package:analyzer/src/plugin/command_line_plugin.dart';
import 'package:analyzer/src/plugin/engine_plugin.dart';
import 'package:analyzer/src/plugin/options_plugin.dart';
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/manager.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/model.dart';
@ -357,6 +359,7 @@ abstract class AnalysisContext {
*
* See [setConfigurationData].
*/
@deprecated
Object/*=V*/ getConfigurationData/*<V>*/(ResultDescriptor/*<V>*/ key);
/**
@ -624,6 +627,7 @@ abstract class AnalysisContext {
*
* See [getConfigurationData].
*/
@deprecated
void setConfigurationData(ResultDescriptor key, Object data);
/**
@ -1150,6 +1154,18 @@ abstract class AnalysisOptions {
*/
bool get enableTiming;
/**
* Return a list of error processors that are to be used when reporting
* errors in some analysis context.
*/
List<ErrorProcessor> get errorProcessors;
/**
* Return a list of exclude patterns used to exclude some sources from
* analysis.
*/
List<String> get excludePatterns;
/**
* A flag indicating whether finer grained dependencies should be used
* instead of just source level dependencies.
@ -1198,6 +1214,12 @@ abstract class AnalysisOptions {
*/
bool get lint;
/**
* Return a list of the lint rules that are to be run in an analysis context
* if [lint] returns `true`.
*/
List<Linter> get lintRules;
/**
* Return the "platform" bit mask which should be used to apply patch files,
* or `0` if no patch files should be applied.
@ -1317,6 +1339,17 @@ class AnalysisOptionsImpl implements AnalysisOptions {
@override
bool enableTiming = false;
/**
* A list of error processors that are to be used when reporting errors in
* some analysis context.
*/
List<ErrorProcessor> _errorProcessors;
/**
* A list of exclude patterns used to exclude some sources from analysis.
*/
List<String> _excludePatterns;
@override
bool generateImplicitErrors = true;
@ -1338,6 +1371,12 @@ class AnalysisOptionsImpl implements AnalysisOptions {
@override
bool lint = false;
/**
* The lint rules that are to be run in an analysis context if [lint] returns
* `true`.
*/
List<Linter> _lintRules;
@override
int patchPlatform = 0;
@ -1410,6 +1449,8 @@ class AnalysisOptionsImpl implements AnalysisOptions {
enableLazyAssignmentOperators = options.enableLazyAssignmentOperators;
enableSuperMixins = options.enableSuperMixins;
enableTiming = options.enableTiming;
errorProcessors = options.errorProcessors;
excludePatterns = options.excludePatterns;
generateImplicitErrors = options.generateImplicitErrors;
generateSdkErrors = options.generateSdkErrors;
hint = options.hint;
@ -1417,6 +1458,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
incrementalApi = options.incrementalApi;
incrementalValidation = options.incrementalValidation;
lint = options.lint;
lintRules = options.lintRules;
preserveComments = options.preserveComments;
strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
@ -1483,6 +1525,40 @@ class AnalysisOptionsImpl implements AnalysisOptions {
@deprecated
void set enableGenericMethods(bool enable) {}
@override
List<ErrorProcessor> get errorProcessors =>
_errorProcessors ??= const <ErrorProcessor>[];
/**
* Set the list of error [processors] that are to be used when reporting
* errors in some analysis context.
*/
void set errorProcessors(List<ErrorProcessor> processors) {
_errorProcessors = processors;
}
@override
List<String> get excludePatterns => _excludePatterns ??= const <String>[];
/**
* Set the exclude patterns used to exclude some sources from analysis to
* those in the given list of [patterns].
*/
void set excludePatterns(List<String> patterns) {
_excludePatterns = patterns;
}
@override
List<Linter> get lintRules => _lintRules ??= const <Linter>[];
/**
* Set the lint rules that are to be run in an analysis context if [lint]
* returns `true`.
*/
void set lintRules(List<Linter> rules) {
_lintRules = rules;
}
@override
List<int> encodeCrossContextOptions() {
int flags = (enableAssertMessage ? ENABLE_ASSERT_FLAG : 0) |

View file

@ -8,5 +8,3 @@ library analyzer.src.generated.error;
export 'package:analyzer/error/error.dart';
export 'package:analyzer/error/listener.dart';
export 'package:analyzer/src/error/codes.dart';
export 'package:analyzer/src/task/options.dart'
show CONFIGURED_ERROR_PROCESSORS;

View file

@ -9,15 +9,6 @@ import 'dart:collection';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/task/model.dart';
import 'package:analyzer/task/model.dart';
const List<Linter> _noLints = const <Linter>[];
/// The descriptor used to associate lints with analysis contexts in
/// configuration data.
final ResultDescriptor<List<Linter>> CONFIGURED_LINTS_KEY =
new ResultDescriptorImpl('configured.lints', _noLints);
/// Shared lint registry.
LintRegistry lintRegistry = new LintRegistry();
@ -25,11 +16,14 @@ LintRegistry lintRegistry = new LintRegistry();
/// Return lints associated with this [context], or an empty list if there are
/// none.
List<Linter> getLints(AnalysisContext context) =>
context.getConfigurationData(CONFIGURED_LINTS_KEY) ?? _noLints;
context.analysisOptions.lintRules;
/// Associate these [lints] with the given [context].
void setLints(AnalysisContext context, List<Linter> lints) {
context.setConfigurationData(CONFIGURED_LINTS_KEY, lints);
AnalysisOptionsImpl options =
new AnalysisOptionsImpl.from(context.analysisOptions);
options.lintRules = lints;
context.analysisOptions = options;
}
/// Implementers contribute lint warnings via the provided error [reporter].

View file

@ -10,7 +10,6 @@ import 'package:analyzer/analyzer.dart';
import 'package:analyzer/plugin/options.dart';
import 'package:analyzer/source/analysis_options_provider.dart';
import 'package:analyzer/source/error_processor.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
@ -29,14 +28,6 @@ final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS =
new ListResultDescriptor<AnalysisError>(
'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS);
/**
* The descriptor used to associate error processors with analysis contexts in
* configuration data.
*/
final ListResultDescriptor<ErrorProcessor> CONFIGURED_ERROR_PROCESSORS =
new ListResultDescriptor<ErrorProcessor>(
'configured.errors', const <ErrorProcessor>[]);
final _OptionsProcessor _processor = new _OptionsProcessor();
void applyToAnalysisOptions(
@ -547,7 +538,10 @@ class _OptionsProcessor {
if (excludes is YamlList) {
List<String> excludeList = toStringList(excludes);
if (excludeList != null) {
context.setConfigurationData(CONTEXT_EXCLUDES, excludeList);
AnalysisOptionsImpl options =
new AnalysisOptionsImpl.from(context.analysisOptions);
options.excludePatterns = excludeList;
context.analysisOptions = options;
}
}
}
@ -595,8 +589,10 @@ class _OptionsProcessor {
void setProcessors(AnalysisContext context, Object codes) {
ErrorConfig config = new ErrorConfig(codes);
context.setConfigurationData(
CONFIGURED_ERROR_PROCESSORS, config.processors);
AnalysisOptionsImpl options =
new AnalysisOptionsImpl.from(context.analysisOptions);
options.errorProcessors = config.processors;
context.analysisOptions = options;
}
void setStrongMode(AnalysisContext context, Object strongMode) {

View file

@ -483,6 +483,7 @@ class TestAnalysisContext implements InternalAnalysisContext {
return null;
}
@deprecated
@override
Object/*=V*/ getConfigurationData/*<V>*/(ResultDescriptor/*<V>*/ key) {
fail("Unexpected invocation of getConfigurationData");
@ -685,6 +686,7 @@ class TestAnalysisContext implements InternalAnalysisContext {
fail("Unexpected invocation of setChangedContents");
}
@deprecated
@override
void setConfigurationData(ResultDescriptor key, Object data) {
fail("Unexpected invocation of setConfigurationData");

View file

@ -977,15 +977,6 @@ main() {}''');
});
}
void test_configurationData() {
var key = new ResultDescriptor('test_key', 'TEST_DEFAULT');
var testData = ['test', 'data'];
context.setConfigurationData(key, testData);
expect(context.getConfigurationData(key), testData);
var unusedKey = new ResultDescriptor('unused_key', 'UNUSED_DEFAULT');
expect(context.getConfigurationData(unusedKey), 'UNUSED_DEFAULT');
}
void test_dispose() {
expect(context.isDisposed, isFalse);
context.dispose();

View file

@ -7,11 +7,8 @@ library analyzer.test.src.task.options_test;
import 'package:analyzer/analyzer.dart';
import 'package:analyzer/source/analysis_options_provider.dart';
import 'package:analyzer/source/error_processor.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/task/options.dart'
show CONFIGURED_ERROR_PROCESSORS;
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer/task/general.dart';
import 'package:analyzer/task/model.dart';
@ -90,8 +87,7 @@ analyzer:
unused_local_variable: error
''');
List<ErrorProcessor> processors =
context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
List<ErrorProcessor> processors = context.analysisOptions.errorProcessors;
expect(processors, hasLength(2));
var unused_local = new AnalysisError(
@ -122,7 +118,7 @@ analyzer:
- 'test/**'
''');
List<String> excludes = context.getConfigurationData(CONTEXT_EXCLUDES);
List<String> excludes = context.analysisOptions.excludePatterns;
expect(excludes, unorderedEquals(['foo/bar.dart', 'test/**']));
}
@ -240,7 +236,9 @@ include: other_options.yaml
}
test_perform_include_bad_value() {
newSource('/other_options.yaml', '''
newSource(
'/other_options.yaml',
'''
analyzer:
errors:
unused_local_variable: ftw

View file

@ -14,7 +14,6 @@ import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer_cli/src/driver.dart';
import 'package:analyzer_cli/src/options.dart';
import 'package:path/path.dart' as path;
@ -427,7 +426,7 @@ const emptyOptionsFile = 'data/empty_options.yaml';
Driver driver;
List<ErrorProcessor> get processors =>
driver.context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
driver.context.analysisOptions.errorProcessors;
/// Convert a file specification from a relative path to an absolute path.
/// Handles the case where the file specification is of the form "$uri|$path".