Get computeError working

R=scheglov@google.com

Review URL: https://codereview.chromium.org//1130763003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45604 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
brianwilkerson@google.com 2015-05-07 18:30:40 +00:00
parent 655545c881
commit e8c5b87478
7 changed files with 518 additions and 36 deletions

View file

@ -762,9 +762,27 @@ class AnalysisContextImpl implements InternalAnalysisContext {
@override
AnalysisErrorInfo getErrors(Source source) {
List<AnalysisError> errors = _getResult(source, DART_ERRORS);
// TODO(brianwilkerson) Figure out how to implement this cleanly. The
// problem is that _getResult doesn't know to go into the individual inputs
// for the task to get their values for tasks that are just merging other
// result values. Therefore, if some, but not all, of the error lists have
// been computed, no errors will be returned by it.
List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
errorLists.add(_getResult(source, BUILD_DIRECTIVES_ERRORS));
errorLists.add(_getResult(source, BUILD_LIBRARY_ERRORS));
errorLists.add(_getResult(source, PARSE_ERRORS));
errorLists.add(_getResult(source, SCAN_ERRORS));
for (Source library in getLibrariesContaining(source)) {
LibrarySpecificUnit unit = new LibrarySpecificUnit(library, source);
errorLists.add(_getResult(unit, BUILD_FUNCTION_TYPE_ALIASES_ERRORS));
errorLists.add(_getResult(unit, HINTS));
errorLists.add(_getResult(unit, RESOLVE_REFERENCES_ERRORS));
errorLists.add(_getResult(unit, RESOLVE_TYPE_NAMES_ERRORS));
errorLists.add(_getResult(unit, VERIFY_ERRORS));
}
LineInfo lineInfo = _getResult(source, LINE_INFO);
return new AnalysisErrorInfoImpl(errors, lineInfo);
return new AnalysisErrorInfoImpl(
AnalysisError.mergeLists(errorLists), lineInfo);
}
@override

View file

@ -191,6 +191,18 @@ class AnalysisError {
buffer.write(_message);
return buffer.toString();
}
/**
* Merge all of the errors in the lists in the given list of [errorLists] into
* a single list of errors.
*/
static List<AnalysisError> mergeLists(List<List<AnalysisError>> errorLists) {
List<AnalysisError> errors = <AnalysisError>[];
for (List<AnalysisError> errorList in errorLists) {
errors.addAll(errorList);
}
return errors;
}
}
/**

View file

@ -72,9 +72,12 @@ class EnginePlugin implements Plugin {
registerExtension(taskId, BuildPublicNamespaceTask.DESCRIPTOR);
registerExtension(taskId, BuildSourceClosuresTask.DESCRIPTOR);
registerExtension(taskId, BuildTypeProviderTask.DESCRIPTOR);
registerExtension(taskId, ContainingLibrariesTask.DESCRIPTOR);
registerExtension(taskId, DartErrorsTask.DESCRIPTOR);
registerExtension(taskId, GatherUsedImportedElementsTask.DESCRIPTOR);
registerExtension(taskId, GatherUsedLocalElementsTask.DESCRIPTOR);
registerExtension(taskId, GenerateHintsTask.DESCRIPTOR);
registerExtension(taskId, LibraryUnitErrorsTask.DESCRIPTOR);
registerExtension(taskId, ParseDartTask.DESCRIPTOR);
registerExtension(taskId, ResolveLibraryTypeNamesTask.DESCRIPTOR);
registerExtension(taskId, ResolveReferencesTask.DESCRIPTOR);

View file

@ -40,8 +40,7 @@ const ResultCachingPolicy AST_CACHING_POLICY =
*/
final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS,
contributesTo: DART_ERRORS);
'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
/**
* The errors produced while building function type aliases.
@ -52,8 +51,7 @@ final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
*/
final ResultDescriptor<List<AnalysisError>> BUILD_FUNCTION_TYPE_ALIASES_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS,
contributesTo: DART_ERRORS);
'BUILD_FUNCTION_TYPE_ALIASES_ERRORS', AnalysisError.NO_ERRORS);
/**
* The errors produced while building a library element.
@ -64,8 +62,7 @@ final ResultDescriptor<List<AnalysisError>> BUILD_FUNCTION_TYPE_ALIASES_ERRORS =
*/
final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS,
contributesTo: DART_ERRORS);
'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS);
/**
* The [ClassElement]s of a [LibrarySpecificUnit].
@ -101,6 +98,14 @@ final ResultDescriptor<List<AnalysisError>> CONSTRUCTORS_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'CONSTRUCTORS_ERRORS', AnalysisError.NO_ERRORS);
/**
* The sources representing the libraries that include a given source as a part.
*
* The result is only available for targets representing a compilation unit.
*/
final ListResultDescriptor<Source> CONTAINING_LIBRARIES =
new ListResultDescriptor<Source>('CONTAINING_LIBRARIES', Source.EMPTY_LIST);
/**
* The [ResultCachingPolicy] for [Element]s.
*/
@ -125,7 +130,7 @@ final ListResultDescriptor<Source> EXPORT_SOURCE_CLOSURE =
*/
final ResultDescriptor<List<AnalysisError>> HINTS =
new ResultDescriptor<List<AnalysisError>>(
'HINT_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS);
'HINT_ERRORS', AnalysisError.NO_ERRORS);
/**
* The sources representing the import closure of a library.
@ -197,6 +202,16 @@ final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 =
new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT5', null,
cachingPolicy: ELEMENT_CACHING_POLICY);
/**
* The analysis errors associated with a compilation unit in a specific library.
*
* The result is only available for targets representing a Dart compilation unit
* in a specific library.
*/
final ResultDescriptor<List<AnalysisError>> LIBRARY_UNIT_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'LIBRARY_UNIT_ERRORS', AnalysisError.NO_ERRORS);
/**
* The errors produced while parsing a compilation unit.
*
@ -206,7 +221,7 @@ final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT5 =
*/
final ResultDescriptor<List<AnalysisError>> PARSE_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'PARSE_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS);
'PARSE_ERRORS', AnalysisError.NO_ERRORS);
/**
* The errors produced while resolving references.
@ -217,8 +232,7 @@ final ResultDescriptor<List<AnalysisError>> PARSE_ERRORS =
*/
final ResultDescriptor<List<AnalysisError>> RESOLVE_REFERENCES_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS,
contributesTo: DART_ERRORS);
'RESOLVE_REFERENCES_ERRORS', AnalysisError.NO_ERRORS);
/**
* The errors produced while resolving type names.
@ -229,8 +243,7 @@ final ResultDescriptor<List<AnalysisError>> RESOLVE_REFERENCES_ERRORS =
*/
final ResultDescriptor<List<AnalysisError>> RESOLVE_TYPE_NAMES_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS,
contributesTo: DART_ERRORS);
'RESOLVE_TYPE_NAMES_ERRORS', AnalysisError.NO_ERRORS);
/**
* The partially resolved [CompilationUnit] associated with a unit.
@ -296,7 +309,7 @@ final ResultDescriptor<CompilationUnit> RESOLVED_UNIT5 =
*/
final ResultDescriptor<List<AnalysisError>> SCAN_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'SCAN_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS);
'SCAN_ERRORS', AnalysisError.NO_ERRORS);
/**
* The [ResultCachingPolicy] for [TOKEN_STREAM].
@ -333,7 +346,7 @@ final ResultDescriptor<UsedLocalElements> USED_LOCAL_ELEMENTS =
*/
final ResultDescriptor<List<AnalysisError>> VERIFY_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'VERIFY_ERRORS', AnalysisError.NO_ERRORS, contributesTo: DART_ERRORS);
'VERIFY_ERRORS', AnalysisError.NO_ERRORS);
/**
* A task that builds implicit constructors for a [ClassElement], or keeps
@ -1626,6 +1639,145 @@ class BuildTypeProviderTask extends SourceBasedAnalysisTask {
}
}
/**
* A task that computes a list of the libraries containing the target source.
*/
class ContainingLibrariesTask extends SourceBasedAnalysisTask {
/**
* The task descriptor describing this kind of task.
*/
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
'ContainingLibrariesTask', createTask, buildInputs,
<ResultDescriptor>[CONTAINING_LIBRARIES]);
ContainingLibrariesTask(
InternalAnalysisContext context, AnalysisTarget target)
: super(context, target);
@override
TaskDescriptor get descriptor => DESCRIPTOR;
@override
void internalPerform() {
// TODO(brianwilkerson) This value can change as new libraries are analyzed
// so we need some way of making sure that this result is removed from the
// cache appropriately.
Source source = getRequiredSource();
outputs[CONTAINING_LIBRARIES] = context.getLibrariesContaining(source);
}
/**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the
* given [target].
*/
static Map<String, TaskInput> buildInputs(Source target) {
return <String, TaskInput>{};
}
/**
* Create a [ContainingLibrariesTask] based on the given [target] in the given
* [context].
*/
static ContainingLibrariesTask createTask(
AnalysisContext context, AnalysisTarget target) {
return new ContainingLibrariesTask(context, target);
}
}
/**
* A task that merges all of the errors for a single source into a single list
* 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.
*/
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask',
createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]);
DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
: super(context, target);
@override
TaskDescriptor get descriptor => DESCRIPTOR;
@override
void internalPerform() {
//
// 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);
}
//
// Record outputs.
//
outputs[DART_ERRORS] = AnalysisError.mergeLists(errorLists);
}
/**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the
* given [target].
*/
static Map<String, TaskInput> buildInputs(Source target) {
return <String, TaskInput>{
BUILD_DIRECTIVES_ERRORS_INPUT: BUILD_DIRECTIVES_ERRORS.of(target),
BUILD_LIBRARY_ERRORS_INPUT: BUILD_LIBRARY_ERRORS.of(target),
PARSE_ERRORS_INPUT: PARSE_ERRORS.of(target),
SCAN_ERRORS_INPUT: SCAN_ERRORS.of(target),
LIBRARY_UNIT_ERRORS_INPUT: CONTAINING_LIBRARIES
.of(target)
.toMap((Source library) {
LibrarySpecificUnit unit = new LibrarySpecificUnit(library, target);
return LIBRARY_UNIT_ERRORS.of(unit);
})
};
}
/**
* Create a [DartErrorsTask] based on the given [target] in the given
* [context].
*/
static DartErrorsTask createTask(
AnalysisContext context, AnalysisTarget target) {
return new DartErrorsTask(context, target);
}
}
/**
* The helper for building the export [Namespace] of a [LibraryElement].
*/
@ -1854,7 +2006,7 @@ class GenerateHintsTask extends SourceBasedAnalysisTask {
/**
* The name of the [RESOLVED_UNIT] input.
*/
static const String UNIT_INPUT = 'UNIT_INPUT';
static const String RESOLVED_UNIT_INPUT = 'RESOLVED_UNIT';
/**
* The name of a list of [USED_LOCAL_ELEMENTS] for each library unit input.
@ -1886,7 +2038,7 @@ class GenerateHintsTask extends SourceBasedAnalysisTask {
//
// Prepare inputs.
//
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
CompilationUnit unit = getRequiredInput(RESOLVED_UNIT_INPUT);
List<UsedImportedElements> usedImportedElementsList =
getRequiredInput(USED_IMPORTED_ELEMENTS_INPUT);
List<UsedLocalElements> usedLocalElementsList =
@ -1939,7 +2091,7 @@ class GenerateHintsTask extends SourceBasedAnalysisTask {
static Map<String, TaskInput> buildInputs(LibrarySpecificUnit target) {
Source libSource = target.library;
return <String, TaskInput>{
UNIT_INPUT: RESOLVED_UNIT.of(target),
RESOLVED_UNIT_INPUT: RESOLVED_UNIT.of(target),
USED_LOCAL_ELEMENTS_INPUT: UNITS.of(libSource).toList((unit) {
LibrarySpecificUnit target = new LibrarySpecificUnit(libSource, unit);
return USED_LOCAL_ELEMENTS.of(target);
@ -1961,6 +2113,95 @@ class GenerateHintsTask extends SourceBasedAnalysisTask {
}
}
/**
* A task that merges all of the errors for a single source into a single list
* of errors.
*/
class LibraryUnitErrorsTask extends SourceBasedAnalysisTask {
/**
* The name of the [BUILD_FUNCTION_TYPE_ALIASES_ERRORS] input.
*/
static const String BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT =
'BUILD_FUNCTION_TYPE_ALIASES_ERRORS';
/**
* The name of the [HINTS] input.
*/
static const String HINTS_INPUT = 'HINTS';
/**
* The name of the [RESOLVE_REFERENCES_ERRORS] input.
*/
static const String RESOLVE_REFERENCES_ERRORS_INPUT =
'RESOLVE_REFERENCES_ERRORS';
/**
* The name of the [RESOLVE_TYPE_NAMES_ERRORS] input.
*/
static const String RESOLVE_TYPE_NAMES_ERRORS_INPUT =
'RESOLVE_TYPE_NAMES_ERRORS';
/**
* The name of the [VERIFY_ERRORS] input.
*/
static const String VERIFY_ERRORS_INPUT = 'VERIFY_ERRORS';
/**
* The task descriptor describing this kind of task.
*/
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
'LibraryUnitErrorsTask', createTask, buildInputs,
<ResultDescriptor>[LIBRARY_UNIT_ERRORS]);
LibraryUnitErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
: super(context, target);
@override
TaskDescriptor get descriptor => DESCRIPTOR;
@override
void internalPerform() {
//
// Prepare inputs.
//
List<List<AnalysisError>> errorLists = <List<AnalysisError>>[];
errorLists.add(getRequiredInput(BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT));
errorLists.add(getRequiredInput(HINTS_INPUT));
errorLists.add(getRequiredInput(RESOLVE_REFERENCES_ERRORS_INPUT));
errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT));
errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT));
//
// Record outputs.
//
outputs[LIBRARY_UNIT_ERRORS] = AnalysisError.mergeLists(errorLists);
}
/**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the
* given [unit].
*/
static Map<String, TaskInput> buildInputs(LibrarySpecificUnit unit) {
return <String, TaskInput>{
BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT:
BUILD_FUNCTION_TYPE_ALIASES_ERRORS.of(unit),
HINTS_INPUT: HINTS.of(unit),
RESOLVE_REFERENCES_ERRORS_INPUT: RESOLVE_REFERENCES_ERRORS.of(unit),
RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit),
VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit)
};
}
/**
* Create a [LibraryUnitErrorsTask] based on the given [target] in the given
* [context].
*/
static LibraryUnitErrorsTask createTask(
AnalysisContext context, AnalysisTarget target) {
return new LibraryUnitErrorsTask(context, target);
}
}
/**
* The memento for [ParseDartTask].
*/
@ -2292,8 +2533,10 @@ class ResolveReferencesTask extends SourceBasedAnalysisTask {
* The task descriptor describing this kind of task.
*/
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
'ResolveReferencesTask', createTask, buildInputs,
<ResultDescriptor>[RESOLVED_UNIT]);
'ResolveReferencesTask', createTask, buildInputs, <ResultDescriptor>[
RESOLVE_REFERENCES_ERRORS,
RESOLVED_UNIT
]);
ResolveReferencesTask(InternalAnalysisContext context, AnalysisTarget target)
: super(context, target);

View file

@ -16,13 +16,11 @@ import 'package:analyzer/task/model.dart';
/**
* The analysis errors associated with a target.
*
* The value combines errors represented by multiple other results.
* The result is only available for targets representing a Dart compilation unit.
*/
// TODO(brianwilkerson) If we want to associate errors with targets smaller than
// a file, we will need other contribution points to collect them. In which case
// we might want to rename this and/or document that it applies to files.
final CompositeResultDescriptor<List<AnalysisError>> DART_ERRORS =
new CompositeResultDescriptor<List<AnalysisError>>('DART_ERRORS');
final ResultDescriptor<List<AnalysisError>> DART_ERRORS =
new ResultDescriptor<List<AnalysisError>>(
'DART_ERRORS', AnalysisError.NO_ERRORS);
/**
* The sources of the libraries that are explicitly imported into a library.

View file

@ -59,7 +59,7 @@ class AnalysisContextImplTest extends AbstractContextTest {
fail('Should have failed');
}
void fail_applyChanges_overriddenSource() {
void test_applyChanges_overriddenSource() {
// Note: addSource adds the source to the contentCache.
Source source = addSource("/test.dart", "library test;");
context.computeErrors(source);
@ -140,13 +140,13 @@ import 'libB.dart';''';
});
}
void fail_computeErrors_dart_none() {
void test_computeErrors_dart_none() {
Source source = addSource("/lib.dart", "library lib;");
List<AnalysisError> errors = context.computeErrors(source);
expect(errors, hasLength(0));
}
void fail_computeErrors_dart_part() {
void test_computeErrors_dart_part() {
Source librarySource =
addSource("/lib.dart", "library lib; part 'part.dart';");
Source partSource = addSource("/part.dart", "part of 'lib';");
@ -156,7 +156,7 @@ import 'libB.dart';''';
expect(errors.length > 0, isTrue);
}
void fail_computeErrors_dart_some() {
void test_computeErrors_dart_some() {
Source source = addSource("/lib.dart", "library 'lib';");
List<AnalysisError> errors = context.computeErrors(source);
expect(errors, isNotNull);
@ -312,7 +312,7 @@ class A {
expect(element, same(myEnum));
}
void fail_getErrors_dart_none() {
void test_getErrors_dart_none() {
Source source = addSource("/lib.dart", "library lib;");
var errorInfo = context.getErrors(source);
expect(errorInfo, isNotNull);
@ -323,18 +323,17 @@ class A {
expect(errors, hasLength(0));
}
void fail_getErrors_dart_some() {
void test_getErrors_dart_some() {
Source source = addSource("/lib.dart", "library 'lib';");
var errorInfo = context.getErrors(source);
expect(errorInfo, isNotNull);
List<AnalysisError> errors = errorInfo.errors;
expect(errors, hasLength(0));
context.computeErrors(source);
errors = errorInfo.errors;
errors = context.computeErrors(source);
expect(errors, hasLength(1));
}
void fail_getErrors_html_none() {
void test_getErrors_html_none() {
Source source = addSource("/test.html", "<html></html>");
AnalysisErrorInfo errorInfo = context.getErrors(source);
expect(errorInfo, isNotNull);

View file

@ -33,9 +33,12 @@ main() {
runReflectiveTests(BuildLibraryElementTaskTest);
runReflectiveTests(BuildPublicNamespaceTaskTest);
runReflectiveTests(BuildTypeProviderTaskTest);
runReflectiveTests(ContainingLibrariesTaskTest);
runReflectiveTests(DartErrorsTaskTest);
runReflectiveTests(GatherUsedImportedElementsTaskTest);
runReflectiveTests(GatherUsedLocalElementsTaskTest);
runReflectiveTests(GenerateHintsTaskTest);
runReflectiveTests(LibraryUnitErrorsTaskTest);
runReflectiveTests(ParseDartTaskTest);
runReflectiveTests(ResolveUnitTypeNamesTaskTest);
runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
@ -1183,6 +1186,148 @@ class BuildTypeProviderTaskTest extends _AbstractDartTaskTest {
}
}
@reflectiveTest
class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
test_buildInputs() {
Map<String, TaskInput> inputs =
ContainingLibrariesTask.buildInputs(emptySource);
expect(inputs, isNotNull);
expect(inputs, isEmpty);
}
test_constructor() {
ContainingLibrariesTask task =
new ContainingLibrariesTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_createTask() {
ContainingLibrariesTask task =
ContainingLibrariesTask.createTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_description() {
ContainingLibrariesTask task =
new ContainingLibrariesTask(null, emptySource);
expect(task.description, isNotNull);
}
test_descriptor() {
TaskDescriptor descriptor = ContainingLibrariesTask.DESCRIPTOR;
expect(descriptor, isNotNull);
}
test_perform_definingCompilationUnit() {
AnalysisTarget library = newSource('/test.dart', 'library test;');
_computeResult(library, INCLUDED_PARTS);
_computeResult(library, CONTAINING_LIBRARIES);
expect(task, new isInstanceOf<ContainingLibrariesTask>());
expect(outputs, hasLength(1));
List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
expect(containingLibraries, unorderedEquals([library]));
}
test_perform_partInMultipleLibraries() {
AnalysisTarget library1 =
newSource('/lib1.dart', 'library test; part "part.dart";');
AnalysisTarget library2 =
newSource('/lib2.dart', 'library test; part "part.dart";');
AnalysisTarget part = newSource('/part.dart', 'part of test;');
_computeResult(library1, INCLUDED_PARTS);
_computeResult(library2, INCLUDED_PARTS);
_computeResult(part, SOURCE_KIND);
_computeResult(part, CONTAINING_LIBRARIES);
expect(task, new isInstanceOf<ContainingLibrariesTask>());
expect(outputs, hasLength(1));
List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
expect(containingLibraries, unorderedEquals([library1, library2]));
}
test_perform_partInSingleLibrary() {
AnalysisTarget library =
newSource('/lib.dart', 'library test; part "part.dart";');
AnalysisTarget part = newSource('/part.dart', 'part of test;');
_computeResult(library, INCLUDED_PARTS);
_computeResult(part, SOURCE_KIND);
_computeResult(part, CONTAINING_LIBRARIES);
expect(task, new isInstanceOf<ContainingLibrariesTask>());
expect(outputs, hasLength(1));
List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
expect(containingLibraries, unorderedEquals([library]));
}
}
@reflectiveTest
class DartErrorsTaskTest extends _AbstractDartTaskTest {
test_buildInputs() {
Map<String, TaskInput> inputs = DartErrorsTask.buildInputs(emptySource);
expect(inputs, isNotNull);
expect(inputs.keys, unorderedEquals([
DartErrorsTask.BUILD_DIRECTIVES_ERRORS_INPUT,
DartErrorsTask.BUILD_LIBRARY_ERRORS_INPUT,
DartErrorsTask.PARSE_ERRORS_INPUT,
DartErrorsTask.SCAN_ERRORS_INPUT,
DartErrorsTask.LIBRARY_UNIT_ERRORS_INPUT
]));
}
test_constructor() {
DartErrorsTask task = new DartErrorsTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_createTask() {
DartErrorsTask task = DartErrorsTask.createTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_description() {
DartErrorsTask task = new DartErrorsTask(null, emptySource);
expect(task.description, isNotNull);
}
test_descriptor() {
TaskDescriptor descriptor = DartErrorsTask.DESCRIPTOR;
expect(descriptor, isNotNull);
}
test_perform_definingCompilationUnit() {
AnalysisTarget library =
newSource('/test.dart', 'library test; import "dart:math";');
_computeResult(library, INCLUDED_PARTS);
_computeResult(library, DART_ERRORS);
expect(task, new isInstanceOf<DartErrorsTask>());
expect(outputs, hasLength(1));
List<AnalysisError> errors = outputs[DART_ERRORS];
expect(errors, hasLength(1));
}
test_perform_partInSingleLibrary() {
AnalysisTarget library = newSource(
'/lib.dart', 'library test; import "dart:math"; part "part.dart";');
AnalysisTarget part =
newSource('/part.dart', 'part of test; class A extends A {}');
_computeResult(library, INCLUDED_PARTS);
_computeResult(library, DART_ERRORS);
_computeResult(part, DART_ERRORS);
expect(task, new isInstanceOf<DartErrorsTask>());
expect(outputs, hasLength(1));
List<AnalysisError> errors = outputs[DART_ERRORS];
// This should contain only the errors in the part file, not the ones in the
// library.
expect(errors, hasLength(1));
}
}
@reflectiveTest
class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest {
UsedImportedElements usedElements;
@ -1458,6 +1603,70 @@ f(A a) {
}
}
@reflectiveTest
class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest {
test_buildInputs() {
Map<String, TaskInput> inputs = LibraryUnitErrorsTask
.buildInputs(new LibrarySpecificUnit(emptySource, emptySource));
expect(inputs, isNotNull);
expect(inputs.keys, unorderedEquals([
LibraryUnitErrorsTask.BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT,
LibraryUnitErrorsTask.HINTS_INPUT,
LibraryUnitErrorsTask.RESOLVE_REFERENCES_ERRORS_INPUT,
LibraryUnitErrorsTask.RESOLVE_TYPE_NAMES_ERRORS_INPUT,
LibraryUnitErrorsTask.VERIFY_ERRORS_INPUT
]));
}
test_constructor() {
LibraryUnitErrorsTask task =
new LibraryUnitErrorsTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_createTask() {
LibraryUnitErrorsTask task =
LibraryUnitErrorsTask.createTask(context, emptySource);
expect(task, isNotNull);
expect(task.context, context);
expect(task.target, emptySource);
}
test_description() {
LibraryUnitErrorsTask task = new LibraryUnitErrorsTask(null, emptySource);
expect(task.description, isNotNull);
}
test_descriptor() {
TaskDescriptor descriptor = LibraryUnitErrorsTask.DESCRIPTOR;
expect(descriptor, isNotNull);
}
test_perform_definingCompilationUnit() {
AnalysisTarget library =
newSource('/test.dart', 'library test; import "dart:math";');
_computeResult(
new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS);
expect(task, new isInstanceOf<LibraryUnitErrorsTask>());
expect(outputs, hasLength(1));
List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
expect(errors, hasLength(1));
}
test_perform_partInSingleLibrary() {
AnalysisTarget library =
newSource('/lib.dart', 'library test; part "part.dart";');
AnalysisTarget part = newSource('/part.dart', 'part of test;');
_computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS);
expect(task, new isInstanceOf<LibraryUnitErrorsTask>());
expect(outputs, hasLength(1));
List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
expect(errors, hasLength(0));
}
}
@reflectiveTest
class ParseDartTaskTest extends _AbstractDartTaskTest {
test_buildInputs() {