Index: pkg/analyzer/test/src/summary/resynthesize_ast_test.dart |
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart |
index cb6cfeb2ec1f3383c446e0e09543cfc5583efae2..da0223841de8f35355489b158f5ded67e63cec36 100644 |
--- a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart |
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart |
@@ -20,6 +20,7 @@ import 'package:analyzer/src/summary/summarize_ast.dart'; |
import 'package:analyzer/src/summary/summarize_elements.dart' |
show PackageBundleAssembler; |
import 'package:analyzer/task/dart.dart' show PARSED_UNIT; |
+import 'package:analyzer/task/general.dart'; |
import 'package:unittest/unittest.dart'; |
import '../../reflective_tests.dart'; |
@@ -37,6 +38,9 @@ main() { |
@reflectiveTest |
class AstInferredTypeTest extends AbstractResynthesizeTest |
with _AstResynthesizeTestMixin, InferredTypeMixin { |
+ @override |
+ bool allowMissingFiles = false; |
+ |
bool get checkPropagatedTypes { |
// AST-based summaries do not yet handle propagated types. |
// TODO(paulberry): fix this. |
@@ -690,6 +694,9 @@ var v = new C().m(1, b: 'bbb', c: 2.0); |
class ResynthesizeAstTest extends ResynthesizeTest |
with _AstResynthesizeTestMixin { |
@override |
+ bool allowMissingFiles = false; |
+ |
+ @override |
bool get checkPropagatedTypes => false; |
@override |
@@ -720,6 +727,8 @@ abstract class _AstResynthesizeTestMixin { |
final Map<String, UnlinkedUnitBuilder> uriToUnit = |
<String, UnlinkedUnitBuilder>{}; |
+ bool get allowMissingFiles; |
+ |
AnalysisContext get context; |
LibraryElementImpl _encodeDecodeLibraryElement(Source source) { |
@@ -743,7 +752,7 @@ abstract class _AstResynthesizeTestMixin { |
Map<String, LinkedLibrary> sdkLibraries = |
SerializedMockSdk.instance.uriToLinkedLibrary; |
LinkedLibrary linkedLibrary = sdkLibraries[absoluteUri]; |
- if (linkedLibrary == null) { |
+ if (linkedLibrary == null && !allowMissingFiles) { |
fail('Linker unexpectedly requested LinkedLibrary for "$absoluteUri".' |
' Libraries available: ${sdkLibraries.keys}'); |
} |
@@ -753,7 +762,7 @@ abstract class _AstResynthesizeTestMixin { |
UnlinkedUnit getUnit(String absoluteUri) { |
UnlinkedUnit unit = uriToUnit[absoluteUri] ?? |
SerializedMockSdk.instance.uriToUnlinkedUnit[absoluteUri]; |
- if (unit == null) { |
+ if (unit == null && !allowMissingFiles) { |
fail('Linker unexpectedly requested unit for "$absoluteUri".'); |
} |
return unit; |
@@ -777,7 +786,8 @@ abstract class _AstResynthesizeTestMixin { |
..addAll(unlinkedSummaries), |
new Map<String, LinkedLibrary>() |
..addAll(SerializedMockSdk.instance.uriToLinkedLibrary) |
- ..addAll(linkedSummaries)); |
+ ..addAll(linkedSummaries), |
+ allowMissingFiles); |
} |
UnlinkedUnit _getUnlinkedUnit(Source source) { |
@@ -790,6 +800,14 @@ abstract class _AstResynthesizeTestMixin { |
} |
} |
return uriToUnit.putIfAbsent(uriStr, () { |
+ int modificationTime = context.computeResult(source, MODIFICATION_TIME); |
+ if (modificationTime < 0) { |
+ // Source does not exist. |
+ if (!allowMissingFiles) { |
+ fail('Unexpectedly tried to get unlinked summary for $source'); |
+ } |
+ return null; |
+ } |
CompilationUnit unit = context.computeResult(source, PARSED_UNIT); |
UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); |
bundleAssembler.addUnlinkedUnit(source, unlinkedUnit); |
@@ -820,14 +838,16 @@ abstract class _AstResynthesizeTestMixin { |
} |
UnlinkedPublicNamespace getImport(String relativeUri) { |
- return getPart(relativeUri).publicNamespace; |
+ return getPart(relativeUri)?.publicNamespace; |
} |
UnlinkedUnit definingUnit = _getUnlinkedUnit(librarySource); |
- LinkedLibraryBuilder linkedLibrary = |
- prelink(definingUnit, getPart, getImport); |
- linkedLibrary.dependencies.skip(1).forEach((LinkedDependency d) { |
- _serializeLibrary(resolveRelativeUri(d.uri)); |
- }); |
+ if (definingUnit != null) { |
+ LinkedLibraryBuilder linkedLibrary = |
+ prelink(definingUnit, getPart, getImport); |
+ linkedLibrary.dependencies.skip(1).forEach((LinkedDependency d) { |
+ _serializeLibrary(resolveRelativeUri(d.uri)); |
+ }); |
+ } |
} |
} |