| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.summary.summarize_ast_test; | 5 library analyzer.test.src.summary.summarize_ast_test; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 11 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 11 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/java_engine.dart'; | |
| 14 import 'package:analyzer/src/generated/parser.dart'; | 13 import 'package:analyzer/src/generated/parser.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/summary/format.dart'; | 15 import 'package:analyzer/src/summary/format.dart'; |
| 17 import 'package:analyzer/src/summary/idl.dart'; | 16 import 'package:analyzer/src/summary/idl.dart'; |
| 18 import 'package:analyzer/src/summary/link.dart'; | 17 import 'package:analyzer/src/summary/link.dart'; |
| 19 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 18 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 20 import 'package:analyzer/src/summary/summarize_ast.dart'; | 19 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 21 import 'package:analyzer/src/summary/summarize_elements.dart'; | 20 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 22 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 23 | 22 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 void addBundle(String path, PackageBundle bundle) { | 305 void addBundle(String path, PackageBundle bundle) { |
| 307 _filesToLink.summaryDataStore.addBundle(path, bundle); | 306 _filesToLink.summaryDataStore.addBundle(path, bundle); |
| 308 } | 307 } |
| 309 | 308 |
| 310 /** | 309 /** |
| 311 * Add the given source file so that it may be referenced by the file under | 310 * Add the given source file so that it may be referenced by the file under |
| 312 * test. | 311 * test. |
| 313 */ | 312 */ |
| 314 Source addNamedSource(String filePath, String contents) { | 313 Source addNamedSource(String filePath, String contents) { |
| 315 CompilationUnit unit = _parseText(contents); | 314 CompilationUnit unit = _parseText(contents); |
| 316 List<int> lineStarts = StringUtilities.computeLineStarts(contents); | 315 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); |
| 317 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit, lineStarts); | |
| 318 _filesToLink.uriToUnit[absUri(filePath)] = unlinkedUnit; | 316 _filesToLink.uriToUnit[absUri(filePath)] = unlinkedUnit; |
| 319 // Tests using SummaryLinkerTest don't actually need the returned | 317 // Tests using SummaryLinkerTest don't actually need the returned |
| 320 // Source, so we can safely return `null`. | 318 // Source, so we can safely return `null`. |
| 321 return null; | 319 return null; |
| 322 } | 320 } |
| 323 | 321 |
| 324 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) { | 322 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) { |
| 325 Uri testDartUri = Uri.parse(absUri(path)); | 323 Uri testDartUri = Uri.parse(absUri(path)); |
| 326 CompilationUnit unit = _parseText(text); | 324 CompilationUnit unit = _parseText(text); |
| 327 List<int> lineStarts = StringUtilities.computeLineStarts(text); | 325 UnlinkedUnitBuilder unlinkedDefiningUnit = serializeAstUnlinked(unit); |
| 328 UnlinkedUnitBuilder unlinkedDefiningUnit = | |
| 329 serializeAstUnlinked(unit, lineStarts); | |
| 330 _filesToLink.uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit; | 326 _filesToLink.uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit; |
| 331 LinkerInputs linkerInputs = new LinkerInputs( | 327 LinkerInputs linkerInputs = new LinkerInputs( |
| 332 allowMissingFiles, | 328 allowMissingFiles, |
| 333 _filesToLink.uriToUnit, | 329 _filesToLink.uriToUnit, |
| 334 testDartUri, | 330 testDartUri, |
| 335 unlinkedDefiningUnit, | 331 unlinkedDefiningUnit, |
| 336 _filesToLink.summaryDataStore.linkedMap, | 332 _filesToLink.summaryDataStore.linkedMap, |
| 337 _filesToLink.summaryDataStore.unlinkedMap); | 333 _filesToLink.summaryDataStore.unlinkedMap); |
| 338 // Reset _filesToLink in case the test needs to start a new package bundle. | 334 // Reset _filesToLink in case the test needs to start a new package bundle. |
| 339 _filesToLink = new _FilesToLink(); | 335 _filesToLink = new _FilesToLink(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 364 return assembler.assemble(); | 360 return assembler.assemble(); |
| 365 } | 361 } |
| 366 | 362 |
| 367 CompilationUnit _parseText(String text) { | 363 CompilationUnit _parseText(String text) { |
| 368 CharSequenceReader reader = new CharSequenceReader(text); | 364 CharSequenceReader reader = new CharSequenceReader(text); |
| 369 Scanner scanner = | 365 Scanner scanner = |
| 370 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); | 366 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); |
| 371 Token token = scanner.tokenize(); | 367 Token token = scanner.tokenize(); |
| 372 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); | 368 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); |
| 373 parser.parseGenericMethods = true; | 369 parser.parseGenericMethods = true; |
| 374 return parser.parseCompilationUnit(token); | 370 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 371 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 372 return unit; |
| 375 } | 373 } |
| 376 } | 374 } |
| 377 | 375 |
| 378 /** | 376 /** |
| 379 * [_FilesToLink] stores information about a set of files to be linked together. | 377 * [_FilesToLink] stores information about a set of files to be linked together. |
| 380 * This information is grouped into a class to allow it to be reset easily when | 378 * This information is grouped into a class to allow it to be reset easily when |
| 381 * [SummaryLinkerTest.createLinkerInputs] is called. | 379 * [SummaryLinkerTest.createLinkerInputs] is called. |
| 382 */ | 380 */ |
| 383 class _FilesToLink { | 381 class _FilesToLink { |
| 384 /** | 382 /** |
| 385 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit | 383 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit |
| 386 * passed to [addNamedSource]. | 384 * passed to [addNamedSource]. |
| 387 */ | 385 */ |
| 388 Map<String, UnlinkedUnitBuilder> uriToUnit = <String, UnlinkedUnitBuilder>{}; | 386 Map<String, UnlinkedUnitBuilder> uriToUnit = <String, UnlinkedUnitBuilder>{}; |
| 389 | 387 |
| 390 /** | 388 /** |
| 391 * Information about summaries to be included in the link process. | 389 * Information about summaries to be included in the link process. |
| 392 */ | 390 */ |
| 393 SummaryDataStore summaryDataStore = new SummaryDataStore([]); | 391 SummaryDataStore summaryDataStore = new SummaryDataStore([]); |
| 394 } | 392 } |
| OLD | NEW |