Reanalyze after creating a referenced part.

We need to finish linking CompilationUnitElement(s) to LibraryElement(s)
even for not existing sources. Otherwise we get NPE later and leave
model in the ERROR state.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org//1168743002
This commit is contained in:
Konstantin Shcheglov 2015-06-05 11:29:04 -07:00
parent e8fe98ecb6
commit 787e9fcf7f
5 changed files with 44 additions and 19 deletions

View file

@ -425,6 +425,15 @@ class CacheEntry {
*/
/*<V>*/ void setValue(ResultDescriptor /*<V>*/ descriptor, dynamic /*V*/
value, List<TargetedResult> dependedOn) {
// {
// String valueStr = '$value';
// if (valueStr.length > 20) {
// valueStr = valueStr.substring(0, 20) + '...';
// }
// valueStr = valueStr.replaceAll('\n', '\\n');
// print(
// 'setValue $descriptor for $target value=$valueStr deps=$dependedOn');
// }
_validateStateChange(descriptor, CacheState.VALID);
TargetedResult thisResult = new TargetedResult(target, descriptor);
if (_partition != null) {
@ -464,6 +473,7 @@ class CacheEntry {
* invalidation to other results that depend on it.
*/
void _invalidate(ResultDescriptor descriptor) {
// print('invalidate $descriptor for $target');
ResultData thisData = _resultMap.remove(descriptor);
if (thisData == null) {
return;

View file

@ -1331,7 +1331,7 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
Source partSource = partDirective.source;
hasPartDirective = true;
CompilationUnit partUnit = partUnitMap[partSource];
if (partUnit != null && context.exists(partSource)) {
if (partUnit != null) {
CompilationUnitElementImpl partElement = partUnit.element;
partElement.uriOffset = partUri.offset;
partElement.uriEnd = partUri.end;
@ -1340,24 +1340,26 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
// Validate that the part contains a part-of directive with the same
// name as the library.
//
String partLibraryName =
_getPartLibraryName(partSource, partUnit, directivesToResolve);
if (partLibraryName == null) {
errors.add(new AnalysisError(librarySource, partUri.offset,
partUri.length, CompileTimeErrorCode.PART_OF_NON_PART,
[partUri.toSource()]));
} else if (libraryNameNode == null) {
if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) {
partsLibraryName = partLibraryName;
} else if (partsLibraryName != partLibraryName) {
partsLibraryName = null;
if (context.exists(partSource)) {
String partLibraryName =
_getPartLibraryName(partSource, partUnit, directivesToResolve);
if (partLibraryName == null) {
errors.add(new AnalysisError(librarySource, partUri.offset,
partUri.length, CompileTimeErrorCode.PART_OF_NON_PART,
[partUri.toSource()]));
} else if (libraryNameNode == null) {
if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) {
partsLibraryName = partLibraryName;
} else if (partsLibraryName != partLibraryName) {
partsLibraryName = null;
}
} else if (libraryNameNode.name != partLibraryName) {
errors.add(new AnalysisError(librarySource, partUri.offset,
partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
libraryNameNode.name,
partLibraryName
]));
}
} else if (libraryNameNode.name != partLibraryName) {
errors.add(new AnalysisError(librarySource, partUri.offset,
partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
libraryNameNode.name,
partLibraryName
]));
}
if (entryPoint == null) {
entryPoint = _findEntryPoint(partElement);

View file

@ -126,6 +126,7 @@ class AnalysisDriver {
}
// Create a new WorkOrder.
TargetedResult request = highestManager.getNextResult();
// print('request: $request');
if (request != null) {
WorkOrder workOrder =
createWorkOrderForResult(request.target, request.result);

View file

@ -473,6 +473,8 @@ library lib;
part 'part.dart';''');
// run all tasks without part
_analyzeAll_assertFinished();
expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)),
isTrue, reason: "lib has errors");
// add part and run all tasks
Source partSource = addSource("/part.dart", r'''
part of lib;
@ -481,6 +483,11 @@ part of lib;
// "libSource" should be here
List<Source> librariesWithPart = context.getLibrariesContaining(partSource);
expect(librariesWithPart, unorderedEquals([libSource]));
expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libSource)),
isFalse, reason: "lib doesn't have errors");
expect(
context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
reason: "part resolved");
}
void test_performAnalysisTask_changeLibraryContents() {

View file

@ -981,7 +981,12 @@ library lib;
part 'no-such-file.dart';
'''
});
expect(libraryElement.parts, isEmpty);
expect(libraryElement.parts, hasLength(1));
CompilationUnitElement part = libraryElement.parts[0];
expect(part, isNotNull);
expect(part.source, isNotNull);
expect(part.library, same(libraryElement));
expect(context.exists(part.source), isFalse);
}
test_perform_patchTopLevelAccessors() {