| 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'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; | 14 import 'package:analyzer/src/generated/parser.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/summary/format.dart'; | 16 import 'package:analyzer/src/summary/format.dart'; |
| 16 import 'package:analyzer/src/summary/idl.dart'; | 17 import 'package:analyzer/src/summary/idl.dart'; |
| 17 import 'package:analyzer/src/summary/link.dart'; | 18 import 'package:analyzer/src/summary/link.dart'; |
| 18 import 'package:analyzer/src/summary/summarize_ast.dart'; | 19 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 19 import 'package:analyzer/src/summary/summarize_elements.dart'; | 20 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 20 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 21 | 22 |
| 22 import '../../reflective_tests.dart'; | 23 import '../../reflective_tests.dart'; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 bundle.unlinkedUnits[i]; | 326 bundle.unlinkedUnits[i]; |
| 326 } | 327 } |
| 327 } | 328 } |
| 328 | 329 |
| 329 /** | 330 /** |
| 330 * Add the given source file so that it may be referenced by the file under | 331 * Add the given source file so that it may be referenced by the file under |
| 331 * test. | 332 * test. |
| 332 */ | 333 */ |
| 333 Source addNamedSource(String filePath, String contents) { | 334 Source addNamedSource(String filePath, String contents) { |
| 334 CompilationUnit unit = _parseText(contents); | 335 CompilationUnit unit = _parseText(contents); |
| 335 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); | 336 List<int> lineStarts = StringUtilities.computeLineStarts(contents); |
| 337 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit, lineStarts); |
| 336 uriToUnit[absUri(filePath)] = unlinkedUnit; | 338 uriToUnit[absUri(filePath)] = unlinkedUnit; |
| 337 // Tests using SummaryLinkerTest don't actually need the returned | 339 // Tests using SummaryLinkerTest don't actually need the returned |
| 338 // Source, so we can safely return `null`. | 340 // Source, so we can safely return `null`. |
| 339 return null; | 341 return null; |
| 340 } | 342 } |
| 341 | 343 |
| 342 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) { | 344 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) { |
| 343 Uri testDartUri = Uri.parse(absUri(path)); | 345 Uri testDartUri = Uri.parse(absUri(path)); |
| 344 CompilationUnit unit = _parseText(text); | 346 CompilationUnit unit = _parseText(text); |
| 345 UnlinkedUnitBuilder unlinkedDefiningUnit = serializeAstUnlinked(unit); | 347 List<int> lineStarts = StringUtilities.computeLineStarts(text); |
| 348 UnlinkedUnitBuilder unlinkedDefiningUnit = |
| 349 serializeAstUnlinked(unit, lineStarts); |
| 346 uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit; | 350 uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit; |
| 347 LinkerInputs linkerInputs = new LinkerInputs( | 351 LinkerInputs linkerInputs = new LinkerInputs( |
| 348 allowMissingFiles, | 352 allowMissingFiles, |
| 349 uriToUnit, | 353 uriToUnit, |
| 350 testDartUri, | 354 testDartUri, |
| 351 unlinkedDefiningUnit, | 355 unlinkedDefiningUnit, |
| 352 _dependentLinkedLibraries, | 356 _dependentLinkedLibraries, |
| 353 _dependentUnlinkedUnits); | 357 _dependentUnlinkedUnits); |
| 354 // Reset uriToUnit, _dependentLinkedLibraries, and _dependentUnlinkedUnits | 358 // Reset uriToUnit, _dependentLinkedLibraries, and _dependentUnlinkedUnits |
| 355 // in case the test needs to start a new package bundle. | 359 // in case the test needs to start a new package bundle. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 386 CompilationUnit _parseText(String text) { | 390 CompilationUnit _parseText(String text) { |
| 387 CharSequenceReader reader = new CharSequenceReader(text); | 391 CharSequenceReader reader = new CharSequenceReader(text); |
| 388 Scanner scanner = | 392 Scanner scanner = |
| 389 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); | 393 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); |
| 390 Token token = scanner.tokenize(); | 394 Token token = scanner.tokenize(); |
| 391 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); | 395 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); |
| 392 parser.parseGenericMethods = true; | 396 parser.parseGenericMethods = true; |
| 393 return parser.parseCompilationUnit(token); | 397 return parser.parseCompilationUnit(token); |
| 394 } | 398 } |
| 395 } | 399 } |
| OLD | NEW |