| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.test.src.summary.summarize_ast_test; |
| 6 |
| 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/src/generated/error.dart'; |
| 10 import 'package:analyzer/src/generated/parser.dart'; |
| 11 import 'package:analyzer/src/generated/scanner.dart'; |
| 12 import 'package:analyzer/src/summary/format.dart'; |
| 13 import 'package:analyzer/src/summary/prelink.dart'; |
| 14 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 15 import 'package:unittest/unittest.dart'; |
| 16 |
| 17 import '../../reflective_tests.dart'; |
| 18 import 'summary_common.dart'; |
| 19 |
| 20 main() { |
| 21 groupSep = ' | '; |
| 22 runReflectiveTests(UnlinkedSummarizeAstTest); |
| 23 } |
| 24 |
| 25 /** |
| 26 * Override of [SummaryTest] which creates unlinked summaries directly from the |
| 27 * AST. |
| 28 */ |
| 29 @reflectiveTest |
| 30 class UnlinkedSummarizeAstTest extends Object with SummaryTest { |
| 31 @override |
| 32 LinkedLibrary linked; |
| 33 |
| 34 @override |
| 35 List<UnlinkedUnit> unlinkedUnits; |
| 36 |
| 37 /** |
| 38 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit |
| 39 * passed to [addNamedSource]. |
| 40 */ |
| 41 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; |
| 42 |
| 43 @override |
| 44 bool get checkAstDerivedData => true; |
| 45 |
| 46 @override |
| 47 bool get expectAbsoluteUrisInDependencies => false; |
| 48 |
| 49 @override |
| 50 bool get skipFullyLinkedData => true; |
| 51 |
| 52 @override |
| 53 addNamedSource(String filePath, String contents) { |
| 54 CompilationUnit unit = _parseText(contents); |
| 55 UnlinkedUnit unlinkedUnit = |
| 56 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); |
| 57 uriToUnit[absUri(filePath)] = unlinkedUnit; |
| 58 } |
| 59 |
| 60 @override |
| 61 void serializeLibraryText(String text, {bool allowErrors: false}) { |
| 62 Uri testDartUri = Uri.parse(absUri('/test.dart')); |
| 63 String resolveToAbsoluteUri(String relativeUri) => |
| 64 testDartUri.resolve(relativeUri).toString(); |
| 65 CompilationUnit unit = _parseText(text); |
| 66 UnlinkedUnit definingUnit = |
| 67 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); |
| 68 UnlinkedUnit getPart(String relativeUri) { |
| 69 String absoluteUri = resolveToAbsoluteUri(relativeUri); |
| 70 UnlinkedUnit unit = uriToUnit[absoluteUri]; |
| 71 if (unit == null && !allowMissingFiles) { |
| 72 fail('Prelinker unexpectedly requested unit for "$relativeUri"' |
| 73 ' (resolves to "$absoluteUri").'); |
| 74 } |
| 75 return unit; |
| 76 } |
| 77 UnlinkedPublicNamespace getImport(String relativeUri) { |
| 78 String absoluteUri = resolveToAbsoluteUri(relativeUri); |
| 79 UnlinkedPublicNamespace namespace = sdkPublicNamespace[absoluteUri]; |
| 80 if (namespace == null) { |
| 81 namespace = uriToUnit[absoluteUri]?.publicNamespace; |
| 82 } |
| 83 if (namespace == null && !allowMissingFiles) { |
| 84 fail('Prelinker unexpectedly requested namespace for "$relativeUri"' |
| 85 ' (resolves to "$absoluteUri").' |
| 86 ' Namespaces available: ${uriToUnit.keys}'); |
| 87 } |
| 88 return namespace; |
| 89 } |
| 90 linked = new LinkedLibrary.fromBuffer( |
| 91 prelink(definingUnit, getPart, getImport).toBuffer()); |
| 92 unlinkedUnits = <UnlinkedUnit>[definingUnit]; |
| 93 for (String relativeUri in definingUnit.publicNamespace.parts) { |
| 94 UnlinkedUnit unit = uriToUnit[resolveToAbsoluteUri(relativeUri)]; |
| 95 if (unit == null) { |
| 96 if (!allowMissingFiles) { |
| 97 fail('Test referred to unknown unit $relativeUri'); |
| 98 } |
| 99 } else { |
| 100 unlinkedUnits.add(unit); |
| 101 } |
| 102 } |
| 103 } |
| 104 |
| 105 CompilationUnit _parseText(String text) { |
| 106 CharSequenceReader reader = new CharSequenceReader(text); |
| 107 Scanner scanner = |
| 108 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); |
| 109 Token token = scanner.tokenize(); |
| 110 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); |
| 111 parser.parseGenericMethods = true; |
| 112 return parser.parseCompilationUnit(token); |
| 113 } |
| 114 } |
| OLD | NEW |