Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/src/context/context.dart'; | 9 import 'package:analyzer/src/context/context.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/driver.dart' as driver; | 11 import 'package:analyzer/src/dart/analysis/driver.dart' as driver; |
| 11 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/summary/idl.dart'; | 16 import 'package:analyzer/src/summary/idl.dart'; |
| 16 import 'package:analyzer/src/summary/summary_sdk.dart'; | 17 import 'package:analyzer/src/summary/summary_sdk.dart'; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 var graph = await graphForProgram([_source], _options); | 67 var graph = await graphForProgram([_source], _options); |
| 67 var libraries = <Uri, ResolvedLibrary>{}; | 68 var libraries = <Uri, ResolvedLibrary>{}; |
| 68 if (!_schedulerStarted) { | 69 if (!_schedulerStarted) { |
| 69 _scheduler.start(); | 70 _scheduler.start(); |
| 70 _schedulerStarted = true; | 71 _schedulerStarted = true; |
| 71 } | 72 } |
| 72 // The driver will request files from dart:, even though it actually uses | 73 // The driver will request files from dart:, even though it actually uses |
| 73 // the data from the summary. TODO(paulberry): fix this. | 74 // the data from the summary. TODO(paulberry): fix this. |
| 74 _fileRepository.store(Uri.parse('dart:core'), ''); | 75 _fileRepository.store(Uri.parse('dart:core'), ''); |
| 75 for (var libraryCycle in graph.topologicallySortedCycles) { | 76 for (var libraryCycle in graph.topologicallySortedCycles) { |
| 76 for (var uri in libraryCycle.libraries.keys) { | 77 for (var libraryUri in libraryCycle.libraries.keys) { |
| 77 var contents = | 78 var libraryNode = libraryCycle.libraries[libraryUri]; |
| 78 await _options.fileSystem.entityForUri(uri).readAsString(); | 79 var libraryContents = |
| 79 _fileRepository.store(uri, contents); | 80 await _options.fileSystem.entityForUri(libraryUri).readAsString(); |
| 81 _fileRepository.store(libraryUri, libraryContents); | |
| 82 for (var partUri in libraryNode.parts) { | |
| 83 var partContents = | |
| 84 await _options.fileSystem.entityForUri(partUri).readAsString(); | |
| 85 _fileRepository.store(partUri, partContents); | |
| 86 } | |
| 80 } | 87 } |
| 81 for (var uri in libraryCycle.libraries.keys) { | 88 for (var libraryUri in libraryCycle.libraries.keys) { |
| 82 var result = await _driver.getResult(_fileRepository.pathForUri(uri)); | 89 var libraryNode = libraryCycle.libraries[libraryUri]; |
| 90 var result = await _driver.getResult(_fileRepository.pathForUri(libraryU ri)); | |
| 83 // TODO(paulberry): handle errors. | 91 // TODO(paulberry): handle errors. |
| 84 libraries[uri] = new ResolvedLibrary(result.unit); | 92 var definingCompilationUnit = result.unit; |
| 93 var partUnits = <Uri, CompilationUnit>{}; | |
| 94 for (var partUri in libraryNode.parts) { | |
| 95 // Really we ought to have a driver API that lets us request a | |
| 96 // specific part of a given library. Otherwise we will run into | |
| 97 // problems if a part is included in multiple libraries. | |
| 98 // TODO(paulberry): address this. | |
| 99 var partResult = await _driver.getResult(_fileRepository.pathForUri(pa rtUri)); | |
| 100 // TODO(paulberry): handle errors. | |
| 101 partUnits[partUri] = partResult.unit; | |
| 102 } | |
| 103 libraries[libraryUri] = | |
| 104 new ResolvedLibrary(definingCompilationUnit, partUnits); | |
| 85 } | 105 } |
| 86 } | 106 } |
| 87 _driver.addFile(_fileRepository.pathForUri(_source)); | 107 _driver.addFile(_fileRepository.pathForUri(_source)); |
| 88 // TODO(paulberry): stop the scheduler | 108 // TODO(paulberry): stop the scheduler |
| 89 return new DeltaLibraries(libraries); | 109 return new DeltaLibraries(libraries); |
| 90 } | 110 } |
| 91 | 111 |
| 92 Future<Null> init() async { | 112 Future<Null> init() async { |
| 93 // TODO(paulberry): can we just use null? | 113 // TODO(paulberry): can we just use null? |
| 94 var performanceLog = new driver.PerformanceLog(new _NullStringSink()); | 114 var performanceLog = new driver.PerformanceLog(new _NullStringSink()); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 Source forUri(String absoluteUri) { | 259 Source forUri(String absoluteUri) { |
| 240 Uri uri = Uri.parse(absoluteUri); | 260 Uri uri = Uri.parse(absoluteUri); |
| 241 return new _SourceProxy(uri, _fileRepository.pathForUri(uri)); | 261 return new _SourceProxy(uri, _fileRepository.pathForUri(uri)); |
| 242 } | 262 } |
| 243 | 263 |
| 244 noSuchMethod(Invocation invocation) => unimplemented(); | 264 noSuchMethod(Invocation invocation) => unimplemented(); |
| 245 | 265 |
| 246 Source resolveUri(Source containingSource, String containedUri) { | 266 Source resolveUri(Source containingSource, String containedUri) { |
| 247 // TODO(paulberry): re-use code from dependency_grapher_impl, and support | 267 // TODO(paulberry): re-use code from dependency_grapher_impl, and support |
| 248 // SDK URI resolution logic. | 268 // SDK URI resolution logic. |
| 249 var absoluteUri = containingSource.uri.resolve(containedUri); | 269 var absoluteUri = containingSource == null |
|
danrubel
2017/01/19 20:06:39
Is absoluteUri dynamic? IOW, will absoluteUri be a
Paul Berry
2017/01/19 20:29:46
Whoops, thanks for catching this. I took your sug
| |
| 270 ? containedUri | |
| 271 : containingSource.uri.resolve(containedUri); | |
| 250 return forUri(absoluteUri.toString()); | 272 return forUri(absoluteUri.toString()); |
| 251 } | 273 } |
| 252 | 274 |
| 253 @override | 275 @override |
| 254 Uri restoreUri(Source source) => source.uri; | 276 Uri restoreUri(Source source) => source.uri; |
| 255 } | 277 } |
| 256 | 278 |
| 257 class _SourceProxy extends BasicSource { | 279 class _SourceProxy extends BasicSource { |
| 258 @override | 280 @override |
| 259 final String fullName; | 281 final String fullName; |
| 260 | 282 |
| 261 _SourceProxy(Uri uri, this.fullName) : super(uri); | 283 _SourceProxy(Uri uri, this.fullName) : super(uri); |
| 262 | 284 |
| 263 int get modificationStamp => 0; | 285 int get modificationStamp => 0; |
| 264 | 286 |
| 265 noSuchMethod(Invocation invocation) => unimplemented(); | 287 noSuchMethod(Invocation invocation) => unimplemented(); |
| 266 } | 288 } |
| OLD | NEW |