Use contributed ResultDescriptor(s) while computing DART_ERRORS.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org//1317213004 .
This commit is contained in:
Konstantin Shcheglov 2015-09-09 15:12:41 -07:00
parent a1d528fae8
commit 12614041e5
3 changed files with 121 additions and 47 deletions

View file

@ -13,6 +13,24 @@ import 'package:analyzer/src/plugin/engine_plugin.dart';
import 'package:analyzer/task/model.dart';
import 'package:plugin/plugin.dart';
/**
* The identifier of the extension point that allows plugins to register new
* analysis error results to compute for a Dart source. The object used as an
* extension must be a [ResultDescriptor].
*/
final String DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID = Plugin.join(
EnginePlugin.UNIQUE_IDENTIFIER,
EnginePlugin.DART_ERRORS_FOR_SOURCE_EXTENSION_POINT);
/**
* The identifier of the extension point that allows plugins to register new
* analysis error results to compute for a Dart library specific unit. The
* object used as an extension must be a [ResultDescriptor].
*/
final String DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID = Plugin.join(
EnginePlugin.UNIQUE_IDENTIFIER,
EnginePlugin.DART_ERRORS_FOR_UNIT_EXTENSION_POINT);
/**
* The identifier of the extension point that allows plugins to register new
* analysis tasks with the analysis engine. The object used as an extension must

View file

@ -20,6 +20,21 @@ import 'package:plugin/plugin.dart';
* defined by the analysis engine.
*/
class EnginePlugin implements Plugin {
/**
* The simple identifier of the extension point that allows plugins to
* register new analysis error results to compute for a Dart source.
*/
static const String DART_ERRORS_FOR_SOURCE_EXTENSION_POINT =
'dartErrorsForSource';
/**
* The simple identifier of the extension point that allows plugins to
* register new analysis error results to compute for a Dart library
* specific unit.
*/
static const String DART_ERRORS_FOR_UNIT_EXTENSION_POINT =
'dartErrorsForUnit';
/**
* The simple identifier of the extension point that allows plugins to
* register new analysis tasks with the analysis engine.
@ -38,6 +53,18 @@ class EnginePlugin implements Plugin {
*/
static const String UNIQUE_IDENTIFIER = 'analysis_engine.core';
/**
* The extension point that allows plugins to register new analysis error
* results for a Dart source.
*/
ExtensionPoint dartErrorsForSourceExtensionPoint;
/**
* The extension point that allows plugins to register new analysis error
* results for a Dart library specific unit.
*/
ExtensionPoint dartErrorsForUnitExtensionPoint;
/**
* The extension point that allows plugins to register new analysis tasks with
* the analysis engine.
@ -55,6 +82,20 @@ class EnginePlugin implements Plugin {
*/
EnginePlugin();
/**
* Return a list containing all of the contributed analysis error result
* descriptors for Dart sources.
*/
List<TaskDescriptor> get dartErrorsForSource =>
dartErrorsForSourceExtensionPoint.extensions;
/**
* Return a list containing all of the contributed analysis error result
* descriptors for Dart library specific units.
*/
List<TaskDescriptor> get dartErrorsForUnit =>
dartErrorsForUnitExtensionPoint.extensions;
/**
* Return a list containing all of the task descriptors that were contributed.
*/
@ -72,6 +113,10 @@ class EnginePlugin implements Plugin {
@override
void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {
dartErrorsForSourceExtensionPoint = registerExtensionPoint(
DART_ERRORS_FOR_SOURCE_EXTENSION_POINT, _validateResultDescriptor);
dartErrorsForUnitExtensionPoint = registerExtensionPoint(
DART_ERRORS_FOR_UNIT_EXTENSION_POINT, _validateResultDescriptor);
taskExtensionPoint =
registerExtensionPoint(TASK_EXTENSION_POINT, _validateTaskExtension);
workManagerFactoryExtensionPoint = registerExtensionPoint(
@ -83,6 +128,21 @@ class EnginePlugin implements Plugin {
void registerExtensions(RegisterExtension registerExtension) {
_registerTaskExtensions(registerExtension);
_registerWorkManagerFactoryExtensions(registerExtension);
_registerDartErrorsForSource(registerExtension);
_registerDartErrorsForUnit(registerExtension);
}
void _registerDartErrorsForSource(RegisterExtension registerExtension) {
String id = DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID;
registerExtension(id, BUILD_DIRECTIVES_ERRORS);
registerExtension(id, BUILD_LIBRARY_ERRORS);
registerExtension(id, PARSE_ERRORS);
registerExtension(id, SCAN_ERRORS);
}
void _registerDartErrorsForUnit(RegisterExtension registerExtension) {
String id = DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID;
registerExtension(id, LIBRARY_UNIT_ERRORS);
}
void _registerTaskExtensions(RegisterExtension registerExtension) {
@ -145,8 +205,19 @@ class EnginePlugin implements Plugin {
}
/**
* Validate the given extension by throwing an [ExtensionError] if it is not a
* valid domain.
* Validate the given extension by throwing an [ExtensionError] if it is not
* a [ResultDescriptor].
*/
void _validateResultDescriptor(Object extension) {
if (extension is! ResultDescriptor) {
String id = taskExtensionPoint.uniqueIdentifier;
throw new ExtensionError('Extensions to $id must be a ResultDescriptor');
}
}
/**
* Validate the given extension by throwing an [ExtensionError] if it is not
* a [TaskDescriptor].
*/
void _validateTaskExtension(Object extension) {
if (extension is! TaskDescriptor) {
@ -156,8 +227,8 @@ class EnginePlugin implements Plugin {
}
/**
* Validate the given extension by throwing an [ExtensionError] if it is not a
* valid domain.
* Validate the given extension by throwing an [ExtensionError] if it is not
* a [WorkManagerFactory].
*/
void _validateWorkManagerFactoryExtension(Object extension) {
if (extension is! WorkManagerFactory) {

View file

@ -21,6 +21,7 @@ import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/scanner.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/plugin/engine_plugin.dart';
import 'package:analyzer/src/task/driver.dart';
import 'package:analyzer/src/task/general.dart';
import 'package:analyzer/src/task/html.dart';
@ -1921,31 +1922,6 @@ class DartDelta extends Delta {
* of errors.
*/
class DartErrorsTask extends SourceBasedAnalysisTask {
/**
* The name of the [BUILD_DIRECTIVES_ERRORS] input.
*/
static const String BUILD_DIRECTIVES_ERRORS_INPUT = 'BUILD_DIRECTIVES_ERRORS';
/**
* The name of the [BUILD_LIBRARY_ERRORS] input.
*/
static const String BUILD_LIBRARY_ERRORS_INPUT = 'BUILD_LIBRARY_ERRORS';
/**
* The name of the [LIBRARY_UNIT_ERRORS] input.
*/
static const String LIBRARY_UNIT_ERRORS_INPUT = 'LIBRARY_UNIT_ERRORS';
/**
* The name of the [PARSE_ERRORS] input.
*/
static const String PARSE_ERRORS_INPUT = 'PARSE_ERRORS';
/**
* The name of the [SCAN_ERRORS] input.
*/
static const String SCAN_ERRORS_INPUT = 'SCAN_ERRORS';
/**
* The task descriptor describing this kind of task.
*/
@ -1960,18 +1936,21 @@ class DartErrorsTask extends SourceBasedAnalysisTask {
@override
void internalPerform() {
List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
//
// Prepare inputs.
//
List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
errorLists.add(getRequiredInput(BUILD_DIRECTIVES_ERRORS_INPUT));
errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT));
errorLists.add(getRequiredInput(PARSE_ERRORS_INPUT));
errorLists.add(getRequiredInput(SCAN_ERRORS_INPUT));
Map<Source, List<AnalysisError>> unitErrors =
getRequiredInput(LIBRARY_UNIT_ERRORS_INPUT);
for (List<AnalysisError> errors in unitErrors.values) {
errorLists.add(errors);
EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
for (ResultDescriptor result in enginePlugin.dartErrorsForSource) {
String inputName = result.name + '_input';
errorLists.add(getRequiredInput(inputName));
}
for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) {
String inputName = result.name + '_input';
Map<Source, List<AnalysisError>> errorMap = getRequiredInput(inputName);
for (List<AnalysisError> errors in errorMap.values) {
errorLists.add(errors);
}
}
//
// Record outputs.
@ -1986,17 +1965,23 @@ class DartErrorsTask extends SourceBasedAnalysisTask {
*/
static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
Source source = target;
return <String, TaskInput>{
BUILD_DIRECTIVES_ERRORS_INPUT: BUILD_DIRECTIVES_ERRORS.of(source),
BUILD_LIBRARY_ERRORS_INPUT: BUILD_LIBRARY_ERRORS.of(source),
PARSE_ERRORS_INPUT: PARSE_ERRORS.of(source),
SCAN_ERRORS_INPUT: SCAN_ERRORS.of(source),
LIBRARY_UNIT_ERRORS_INPUT:
Map<String, TaskInput> inputs = <String, TaskInput>{};
EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
// for Source
for (ResultDescriptor result in enginePlugin.dartErrorsForSource) {
String inputName = result.name + '_input';
inputs[inputName] = result.of(source);
}
// for LibrarySpecificUnit
for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) {
String inputName = result.name + '_input';
inputs[inputName] =
CONTAINING_LIBRARIES.of(source).toMap((Source library) {
LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source);
return LIBRARY_UNIT_ERRORS.of(unit);
})
};
return result.of(unit);
});
}
return inputs;
}
/**