OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.src.generated.sdk_io; | 5 library analyzer.src.generated.sdk_io; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
11 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
12 import 'package:analyzer/src/dart/scanner/reader.dart'; | 12 import 'package:analyzer/src/dart/scanner/reader.dart'; |
13 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 13 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
16 import 'package:analyzer/src/generated/java_core.dart'; | 16 import 'package:analyzer/src/generated/java_core.dart'; |
17 import 'package:analyzer/src/generated/java_engine.dart'; | 17 import 'package:analyzer/src/generated/java_engine.dart'; |
18 import 'package:analyzer/src/generated/java_engine_io.dart'; | 18 import 'package:analyzer/src/generated/java_engine_io.dart'; |
19 import 'package:analyzer/src/generated/java_io.dart'; | 19 import 'package:analyzer/src/generated/java_io.dart'; |
20 import 'package:analyzer/src/generated/parser.dart'; | 20 import 'package:analyzer/src/generated/parser.dart'; |
21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
22 import 'package:analyzer/src/generated/source_io.dart'; | 22 import 'package:analyzer/src/generated/source_io.dart'; |
23 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; | 23 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; |
24 import 'package:analyzer/src/summary/summary_sdk.dart'; | 24 import 'package:analyzer/src/summary/summary_sdk.dart'; |
25 import 'package:path/path.dart' as pathos; | 25 import 'package:path/path.dart' as pathos; |
26 | 26 |
27 /** | 27 /** |
28 * An abstract implementation of a Dart SDK in which the available libraries are | |
29 * stored in a library map. Subclasses are responsible for populating the | |
30 * library map. | |
31 */ | |
32 abstract class AbstractDartSdk implements DartSdk { | |
33 /** | |
34 * A mapping from Dart library URI's to the library represented by that URI. | |
35 */ | |
36 LibraryMap libraryMap = new LibraryMap(); | |
pquitslund
2016/06/14 17:50:59
Any reason not to make this final?
Brian Wilkerson
2016/06/14 20:53:03
Yes. Unless we change it, DirectoryBasedDartSdk cr
| |
37 | |
38 /** | |
39 * The [AnalysisOptions] to use to create the [context]. | |
40 */ | |
41 AnalysisOptions _analysisOptions; | |
42 | |
43 /** | |
44 * The flag that specifies whether an SDK summary should be used. This is a | |
45 * temporary flag until summaries are enabled by default. | |
46 */ | |
47 bool _useSummary = false; | |
48 | |
49 /** | |
50 * The [AnalysisContext] which is used for all of the sources in this sdk. | |
pquitslund
2016/06/14 17:50:59
sdk => SDK ?
Brian Wilkerson
2016/06/14 20:53:03
Done
| |
51 */ | |
52 InternalAnalysisContext _analysisContext; | |
53 | |
54 /** | |
55 * The mapping from Dart URI's to the corresponding sources. | |
56 */ | |
57 Map<String, Source> _uriToSourceMap = new HashMap<String, Source>(); | |
58 | |
59 /** | |
60 * Set the [options] for this SDK analysis context. Throw [StateError] if the | |
61 * context has been already created. | |
62 */ | |
63 void set analysisOptions(AnalysisOptions options) { | |
64 if (_analysisContext != null) { | |
65 throw new StateError( | |
66 'Analysis options cannot be changed after context creation.'); | |
67 } | |
68 _analysisOptions = options; | |
69 } | |
70 | |
71 @override | |
72 AnalysisContext get context { | |
73 if (_analysisContext == null) { | |
74 _analysisContext = new SdkAnalysisContext(_analysisOptions); | |
75 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | |
76 _analysisContext.sourceFactory = factory; | |
77 if (_useSummary) { | |
78 bool strongMode = _analysisOptions?.strongMode ?? false; | |
79 PackageBundle sdkBundle = getSummarySdkBundle(strongMode); | |
80 if (sdkBundle != null) { | |
81 _analysisContext.resultProvider = new SdkSummaryResultProvider( | |
82 _analysisContext, sdkBundle, strongMode); | |
83 } | |
84 } | |
85 } | |
86 return _analysisContext; | |
87 } | |
88 | |
89 @override | |
90 List<SdkLibrary> get sdkLibraries => libraryMap.sdkLibraries; | |
91 | |
92 @override | |
93 List<String> get uris => libraryMap.uris; | |
94 | |
95 /** | |
96 * Return `true` if the SDK summary will be used when available. | |
97 */ | |
98 bool get useSummary => _useSummary; | |
99 | |
100 /** | |
101 * Specify whether SDK summary should be used. | |
102 */ | |
103 void set useSummary(bool use) { | |
104 if (_analysisContext != null) { | |
105 throw new StateError( | |
106 'The "useSummary" flag cannot be changed after context creation.'); | |
107 } | |
108 _useSummary = use; | |
109 } | |
110 | |
111 @override | |
112 Source fromFileUri(Uri uri) { | |
113 JavaFile file = new JavaFile.fromUri(uri); | |
114 | |
115 String path = _getPath(file); | |
116 if (path == null) { | |
117 return null; | |
118 } | |
119 try { | |
120 return new FileBasedSource(file, parseUriWithException(path)); | |
121 } on URISyntaxException catch (exception, stackTrace) { | |
122 AnalysisEngine.instance.logger.logInformation( | |
123 "Failed to create URI: $path", | |
124 new CaughtException(exception, stackTrace)); | |
125 } | |
126 return null; | |
127 } | |
128 | |
129 String getRelativePathFromFile(JavaFile file); | |
130 | |
131 @override | |
132 SdkLibrary getSdkLibrary(String dartUri) => libraryMap.getLibrary(dartUri); | |
133 | |
134 /** | |
135 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. | |
136 * This method should not be used outside of `analyzer` and `analyzer_cli` | |
137 * packages. | |
138 */ | |
139 PackageBundle getSummarySdkBundle(bool strongMode); | |
140 | |
141 FileBasedSource internalMapDartUri(String dartUri) { | |
142 // TODO(brianwilkerson) Figure out how to unify the implementations in the | |
143 // two subclasses. | |
144 String libraryName; | |
145 String relativePath; | |
146 int index = dartUri.indexOf('/'); | |
147 if (index >= 0) { | |
148 libraryName = dartUri.substring(0, index); | |
149 relativePath = dartUri.substring(index + 1); | |
150 } else { | |
151 libraryName = dartUri; | |
152 relativePath = ""; | |
153 } | |
154 SdkLibrary library = getSdkLibrary(libraryName); | |
155 if (library == null) { | |
156 return null; | |
157 } | |
158 String srcPath; | |
159 if (relativePath.isEmpty) { | |
160 srcPath = library.path; | |
161 } else { | |
162 String libraryPath = library.path; | |
163 int index = libraryPath.lastIndexOf(JavaFile.separator); | |
164 if (index == -1) { | |
165 index = libraryPath.lastIndexOf('/'); | |
166 if (index == -1) { | |
167 return null; | |
168 } | |
169 } | |
170 String prefix = libraryPath.substring(0, index + 1); | |
171 srcPath = '$prefix$relativePath'; | |
172 } | |
173 String filePath = srcPath.replaceAll('/', JavaFile.separator); | |
174 try { | |
175 JavaFile file = new JavaFile(filePath); | |
176 return new FileBasedSource(file, parseUriWithException(dartUri)); | |
177 } on URISyntaxException { | |
178 return null; | |
179 } | |
180 } | |
181 | |
182 @override | |
183 Source mapDartUri(String dartUri) { | |
184 Source source = _uriToSourceMap[dartUri]; | |
185 if (source == null) { | |
186 source = internalMapDartUri(dartUri); | |
187 _uriToSourceMap[dartUri] = source; | |
188 } | |
189 return source; | |
190 } | |
191 | |
192 String _getPath(JavaFile file) { | |
193 List<SdkLibrary> libraries = libraryMap.sdkLibraries; | |
194 int length = libraries.length; | |
195 List<String> paths = new List(length); | |
196 String filePath = getRelativePathFromFile(file); | |
197 if (filePath == null) { | |
198 return null; | |
199 } | |
200 for (int i = 0; i < length; i++) { | |
201 SdkLibrary library = libraries[i]; | |
202 String libraryPath = library.path.replaceAll('/', JavaFile.separator); | |
203 if (filePath == libraryPath) { | |
204 return library.shortName; | |
205 } | |
206 paths[i] = libraryPath; | |
207 } | |
208 for (int i = 0; i < length; i++) { | |
209 SdkLibrary library = libraries[i]; | |
210 String libraryPath = paths[i]; | |
211 int index = libraryPath.lastIndexOf(JavaFile.separator); | |
212 if (index >= 0) { | |
213 String prefix = libraryPath.substring(0, index + 1); | |
214 if (filePath.startsWith(prefix)) { | |
215 String relPath = filePath | |
216 .substring(prefix.length) | |
217 .replaceAll(JavaFile.separator, '/'); | |
218 return '${library.shortName}/$relPath'; | |
219 } | |
220 } | |
221 } | |
222 return null; | |
223 } | |
224 } | |
225 | |
226 /** | |
28 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is | 227 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is |
29 * something like... | 228 * something like... |
30 * | 229 * |
31 * dart-sdk/ | 230 * dart-sdk/ |
32 * bin/ | 231 * bin/ |
33 * dart[.exe] <-- VM | 232 * dart[.exe] <-- VM |
34 * lib/ | 233 * lib/ |
35 * core/ | 234 * core/ |
36 * core.dart | 235 * core.dart |
37 * ... other core library files ... | 236 * ... other core library files ... |
38 * ... other libraries ... | 237 * ... other libraries ... |
39 * util/ | 238 * util/ |
40 * ... Dart utilities ... | 239 * ... Dart utilities ... |
41 * Chromium/ <-- Dartium typically exists in a sibling directory | 240 * Chromium/ <-- Dartium typically exists in a sibling directory |
42 */ | 241 */ |
43 class DirectoryBasedDartSdk implements DartSdk { | 242 class DirectoryBasedDartSdk extends AbstractDartSdk { |
44 /** | 243 /** |
45 * The default SDK, or `null` if the default SDK either has not yet been | 244 * The default SDK, or `null` if the default SDK either has not yet been |
46 * created or cannot be created for some reason. | 245 * created or cannot be created for some reason. |
47 */ | 246 */ |
48 static DirectoryBasedDartSdk _DEFAULT_SDK; | 247 static DirectoryBasedDartSdk _DEFAULT_SDK; |
49 | 248 |
50 /** | 249 /** |
51 * The name of the directory within the SDK directory that contains | 250 * The name of the directory within the SDK directory that contains |
52 * executables. | 251 * executables. |
53 */ | 252 */ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 return null; | 385 return null; |
187 } | 386 } |
188 JavaFile sdkDirectory = new JavaFile(sdkProperty); | 387 JavaFile sdkDirectory = new JavaFile(sdkProperty); |
189 if (!sdkDirectory.exists()) { | 388 if (!sdkDirectory.exists()) { |
190 return null; | 389 return null; |
191 } | 390 } |
192 return sdkDirectory; | 391 return sdkDirectory; |
193 } | 392 } |
194 | 393 |
195 /** | 394 /** |
196 * The [AnalysisContext] which is used for all of the sources in this sdk. | |
197 */ | |
198 InternalAnalysisContext _analysisContext; | |
199 | |
200 /** | |
201 * The directory containing the SDK. | 395 * The directory containing the SDK. |
202 */ | 396 */ |
203 JavaFile _sdkDirectory; | 397 JavaFile _sdkDirectory; |
204 | 398 |
205 /** | 399 /** |
206 * The directory within the SDK directory that contains the libraries. | 400 * The directory within the SDK directory that contains the libraries. |
207 */ | 401 */ |
208 JavaFile _libraryDirectory; | 402 JavaFile _libraryDirectory; |
209 | 403 |
210 /** | 404 /** |
211 * The flag that specifies whether SDK summary should be used. | |
212 */ | |
213 bool _useSummary = false; | |
214 | |
215 /** | |
216 * The revision number of this SDK, or `"0"` if the revision number cannot be | 405 * The revision number of this SDK, or `"0"` if the revision number cannot be |
217 * discovered. | 406 * discovered. |
218 */ | 407 */ |
219 String _sdkVersion; | 408 String _sdkVersion; |
220 | 409 |
221 /** | 410 /** |
222 * The file containing the dart2js executable. | 411 * The file containing the dart2js executable. |
223 */ | 412 */ |
224 JavaFile _dart2jsExecutable; | 413 JavaFile _dart2jsExecutable; |
225 | 414 |
226 /** | 415 /** |
227 * The file containing the Dartium executable. | 416 * The file containing the Dartium executable. |
228 */ | 417 */ |
229 JavaFile _dartiumExecutable; | 418 JavaFile _dartiumExecutable; |
230 | 419 |
231 /** | 420 /** |
232 * The file containing the pub executable. | 421 * The file containing the pub executable. |
233 */ | 422 */ |
234 JavaFile _pubExecutable; | 423 JavaFile _pubExecutable; |
235 | 424 |
236 /** | 425 /** |
237 * The file containing the VM executable. | 426 * The file containing the VM executable. |
238 */ | 427 */ |
239 JavaFile _vmExecutable; | 428 JavaFile _vmExecutable; |
240 | 429 |
241 /** | 430 /** |
242 * A mapping from Dart library URI's to the library represented by that URI. | |
243 */ | |
244 LibraryMap _libraryMap; | |
245 | |
246 /** | |
247 * The mapping from Dart URI's to the corresponding sources. | |
248 */ | |
249 Map<String, Source> _uriToSourceMap = new HashMap<String, Source>(); | |
250 | |
251 /** | |
252 * The [AnalysisOptions] to use to create the [context]. | |
253 */ | |
254 AnalysisOptions _analysisOptions; | |
255 | |
256 /** | |
257 * Initialize a newly created SDK to represent the Dart SDK installed in the | 431 * Initialize a newly created SDK to represent the Dart SDK installed in the |
258 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path | 432 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path |
259 * should be used when it is available | 433 * should be used when it is available |
260 */ | 434 */ |
261 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 435 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
262 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 436 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
263 _libraryMap = initialLibraryMap(useDart2jsPaths); | 437 libraryMap = initialLibraryMap(useDart2jsPaths); |
264 } | 438 } |
265 | 439 |
266 /** | 440 /** |
267 * Set the [options] for this SDK analysis context. Throw [StateError] if the | |
268 * context has been already created. | |
269 */ | |
270 void set analysisOptions(AnalysisOptions options) { | |
271 if (_analysisContext != null) { | |
272 throw new StateError( | |
273 'Analysis options cannot be changed after context creation.'); | |
274 } | |
275 _analysisOptions = options; | |
276 } | |
277 | |
278 @override | |
279 AnalysisContext get context { | |
280 if (_analysisContext == null) { | |
281 _analysisContext = new SdkAnalysisContext(_analysisOptions); | |
282 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | |
283 _analysisContext.sourceFactory = factory; | |
284 if (_useSummary) { | |
285 PackageBundle sdkBundle = getSummarySdkBundle(); | |
286 if (sdkBundle != null) { | |
287 bool strongMode = _analysisOptions?.strongMode ?? false; | |
288 _analysisContext.resultProvider = new SdkSummaryResultProvider( | |
289 _analysisContext, sdkBundle, strongMode); | |
290 } | |
291 } | |
292 } | |
293 return _analysisContext; | |
294 } | |
295 | |
296 /** | |
297 * Return the file containing the dart2js executable, or `null` if it does not | 441 * Return the file containing the dart2js executable, or `null` if it does not |
298 * exist. | 442 * exist. |
299 */ | 443 */ |
300 JavaFile get dart2JsExecutable { | 444 JavaFile get dart2JsExecutable { |
301 if (_dart2jsExecutable == null) { | 445 if (_dart2jsExecutable == null) { |
302 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( | 446 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( |
303 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 447 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
304 OSUtilities.isWindows() | 448 OSUtilities.isWindows() |
305 ? _DART2JS_EXECUTABLE_NAME_WIN | 449 ? _DART2JS_EXECUTABLE_NAME_WIN |
306 : _DART2JS_EXECUTABLE_NAME)); | 450 : _DART2JS_EXECUTABLE_NAME)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 if (_pubExecutable == null) { | 523 if (_pubExecutable == null) { |
380 _pubExecutable = _verifyExecutable(new JavaFile.relative( | 524 _pubExecutable = _verifyExecutable(new JavaFile.relative( |
381 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 525 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
382 OSUtilities.isWindows() | 526 OSUtilities.isWindows() |
383 ? _PUB_EXECUTABLE_NAME_WIN | 527 ? _PUB_EXECUTABLE_NAME_WIN |
384 : _PUB_EXECUTABLE_NAME)); | 528 : _PUB_EXECUTABLE_NAME)); |
385 } | 529 } |
386 return _pubExecutable; | 530 return _pubExecutable; |
387 } | 531 } |
388 | 532 |
389 @override | |
390 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; | |
391 | |
392 /** | 533 /** |
393 * Return the revision number of this SDK, or `"0"` if the revision number | 534 * Return the revision number of this SDK, or `"0"` if the revision number |
394 * cannot be discovered. | 535 * cannot be discovered. |
395 */ | 536 */ |
396 @override | 537 @override |
397 String get sdkVersion { | 538 String get sdkVersion { |
398 if (_sdkVersion == null) { | 539 if (_sdkVersion == null) { |
399 _sdkVersion = DartSdk.DEFAULT_VERSION; | 540 _sdkVersion = DartSdk.DEFAULT_VERSION; |
400 JavaFile revisionFile = | 541 JavaFile revisionFile = |
401 new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); | 542 new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); |
402 try { | 543 try { |
403 String revision = revisionFile.readAsStringSync(); | 544 String revision = revisionFile.readAsStringSync(); |
404 if (revision != null) { | 545 if (revision != null) { |
405 _sdkVersion = revision.trim(); | 546 _sdkVersion = revision.trim(); |
406 } | 547 } |
407 } on FileSystemException { | 548 } on FileSystemException { |
408 // Fall through to return the default. | 549 // Fall through to return the default. |
409 } | 550 } |
410 } | 551 } |
411 return _sdkVersion; | 552 return _sdkVersion; |
412 } | 553 } |
413 | 554 |
414 @override | |
415 List<String> get uris => _libraryMap.uris; | |
416 | |
417 /** | |
418 * Whether an SDK summary should be used. | |
419 */ | |
420 bool get useSummary => _useSummary; | |
421 | |
422 /** | |
423 * Specify whether SDK summary should be used. | |
424 */ | |
425 void set useSummary(bool use) { | |
426 if (_analysisContext != null) { | |
427 throw new StateError( | |
428 'The "useSummary" flag cannot be changed after context creation.'); | |
429 } | |
430 _useSummary = use; | |
431 } | |
432 | |
433 /** | 555 /** |
434 * Return the name of the file containing the VM executable. | 556 * Return the name of the file containing the VM executable. |
435 */ | 557 */ |
436 String get vmBinaryName { | 558 String get vmBinaryName { |
437 if (OSUtilities.isWindows()) { | 559 if (OSUtilities.isWindows()) { |
438 return _VM_EXECUTABLE_NAME_WIN; | 560 return _VM_EXECUTABLE_NAME_WIN; |
439 } else { | 561 } else { |
440 return _VM_EXECUTABLE_NAME; | 562 return _VM_EXECUTABLE_NAME; |
441 } | 563 } |
442 } | 564 } |
(...skipping 20 matching lines...) Expand all Loading... | |
463 new JavaFile.relative( | 585 new JavaFile.relative( |
464 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | 586 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
465 _SDK_LIBRARY_METADATA_DIR), | 587 _SDK_LIBRARY_METADATA_DIR), |
466 _SDK_LIBRARY_METADATA_LIB_DIR), | 588 _SDK_LIBRARY_METADATA_LIB_DIR), |
467 _LIBRARIES_FILE); | 589 _LIBRARIES_FILE); |
468 yield new JavaFile.relative( | 590 yield new JavaFile.relative( |
469 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | 591 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
470 _LIBRARIES_FILE); | 592 _LIBRARIES_FILE); |
471 } | 593 } |
472 | 594 |
473 @override | |
474 Source fromFileUri(Uri uri) { | |
475 JavaFile file = new JavaFile.fromUri(uri); | |
476 String filePath = file.getAbsolutePath(); | |
477 String libPath = libraryDirectory.getAbsolutePath(); | |
478 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { | |
479 return null; | |
480 } | |
481 filePath = filePath.substring(libPath.length + 1); | |
482 for (SdkLibrary library in _libraryMap.sdkLibraries) { | |
483 String libraryPath = library.path; | |
484 if (filePath.replaceAll('\\', '/') == libraryPath) { | |
485 String path = library.shortName; | |
486 try { | |
487 return new FileBasedSource(file, parseUriWithException(path)); | |
488 } on URISyntaxException catch (exception, stackTrace) { | |
489 AnalysisEngine.instance.logger.logInformation( | |
490 "Failed to create URI: $path", | |
491 new CaughtException(exception, stackTrace)); | |
492 return null; | |
493 } | |
494 } | |
495 libraryPath = new JavaFile(library.path).getParent(); | |
496 if (filePath.startsWith("$libraryPath${JavaFile.separator}")) { | |
497 String path = | |
498 "${library.shortName}/${filePath.substring(libraryPath.length + 1)}" ; | |
499 try { | |
500 return new FileBasedSource(file, parseUriWithException(path)); | |
501 } on URISyntaxException catch (exception, stackTrace) { | |
502 AnalysisEngine.instance.logger.logInformation( | |
503 "Failed to create URI: $path", | |
504 new CaughtException(exception, stackTrace)); | |
505 return null; | |
506 } | |
507 } | |
508 } | |
509 return null; | |
510 } | |
511 | |
512 /** | 595 /** |
513 * Return the directory where dartium can be found (the directory that will be | 596 * Return the directory where dartium can be found (the directory that will be |
514 * the working directory if Dartium is invoked without changing the default), | 597 * the working directory if Dartium is invoked without changing the default), |
515 * assuming that the Editor was installed in the [installDir]. | 598 * assuming that the Editor was installed in the [installDir]. |
516 */ | 599 */ |
517 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => | 600 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => |
518 new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); | 601 new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); |
519 | 602 |
520 /** | 603 /** |
521 * Return the auxiliary documentation file for the library with the given | 604 * Return the auxiliary documentation file for the library with the given |
522 * [libraryName], or `null` if no such file exists. | 605 * [libraryName], or `null` if no such file exists. |
523 */ | 606 */ |
524 JavaFile getDocFileFor(String libraryName) { | 607 JavaFile getDocFileFor(String libraryName) { |
525 JavaFile dir = docDirectory; | 608 JavaFile dir = docDirectory; |
526 if (!dir.exists()) { | 609 if (!dir.exists()) { |
527 return null; | 610 return null; |
528 } | 611 } |
529 JavaFile libDir = new JavaFile.relative(dir, libraryName); | 612 JavaFile libDir = new JavaFile.relative(dir, libraryName); |
530 JavaFile docFile = | 613 JavaFile docFile = |
531 new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); | 614 new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); |
532 if (docFile.exists()) { | 615 if (docFile.exists()) { |
533 return docFile; | 616 return docFile; |
534 } | 617 } |
535 return null; | 618 return null; |
536 } | 619 } |
537 | 620 |
538 @override | 621 @override |
539 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); | 622 String getRelativePathFromFile(JavaFile file) { |
623 String filePath = file.getAbsolutePath(); | |
624 String libPath = libraryDirectory.getAbsolutePath(); | |
625 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { | |
626 return null; | |
627 } | |
628 return filePath.substring(libPath.length + 1); | |
629 } | |
540 | 630 |
541 /** | 631 /** |
542 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. | 632 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
543 * This method should not be used outside of `analyzer` and `analyzer_cli` | 633 * This method should not be used outside of `analyzer` and `analyzer_cli` |
544 * packages. | 634 * packages. |
545 */ | 635 */ |
546 PackageBundle getSummarySdkBundle() { | 636 PackageBundle getSummarySdkBundle(bool strongMode) { |
547 String rootPath = directory.getAbsolutePath(); | 637 String rootPath = directory.getAbsolutePath(); |
548 bool strongMode = _analysisOptions?.strongMode ?? false; | |
549 String name = strongMode ? 'strong.sum' : 'spec.sum'; | 638 String name = strongMode ? 'strong.sum' : 'spec.sum'; |
550 String path = pathos.join(rootPath, 'lib', '_internal', name); | 639 String path = pathos.join(rootPath, 'lib', '_internal', name); |
551 try { | 640 try { |
552 File file = new File(path); | 641 File file = new File(path); |
553 if (file.existsSync()) { | 642 if (file.existsSync()) { |
554 List<int> bytes = file.readAsBytesSync(); | 643 List<int> bytes = file.readAsBytesSync(); |
555 return new PackageBundle.fromBuffer(bytes); | 644 return new PackageBundle.fromBuffer(bytes); |
556 } | 645 } |
557 } catch (exception, stackTrace) { | 646 } catch (exception, stackTrace) { |
558 AnalysisEngine.instance.logger.logError( | 647 AnalysisEngine.instance.logger.logError( |
(...skipping 23 matching lines...) Expand all Loading... | |
582 lastStackTrace = stackTrace; | 671 lastStackTrace = stackTrace; |
583 } | 672 } |
584 } | 673 } |
585 AnalysisEngine.instance.logger.logError( | 674 AnalysisEngine.instance.logger.logError( |
586 "Could not initialize the library map from $searchedPaths", | 675 "Could not initialize the library map from $searchedPaths", |
587 new CaughtException(lastException, lastStackTrace)); | 676 new CaughtException(lastException, lastStackTrace)); |
588 return new LibraryMap(); | 677 return new LibraryMap(); |
589 } | 678 } |
590 | 679 |
591 @override | 680 @override |
592 Source mapDartUri(String dartUri) { | 681 FileBasedSource internalMapDartUri(String dartUri) { |
593 Source source = _uriToSourceMap[dartUri]; | |
594 if (source == null) { | |
595 source = _mapDartUri(dartUri); | |
596 _uriToSourceMap[dartUri] = source; | |
597 } | |
598 return source; | |
599 } | |
600 | |
601 FileBasedSource _mapDartUri(String dartUri) { | |
602 String libraryName; | 682 String libraryName; |
603 String relativePath; | 683 String relativePath; |
604 int index = dartUri.indexOf('/'); | 684 int index = dartUri.indexOf('/'); |
605 if (index >= 0) { | 685 if (index >= 0) { |
606 libraryName = dartUri.substring(0, index); | 686 libraryName = dartUri.substring(0, index); |
607 relativePath = dartUri.substring(index + 1); | 687 relativePath = dartUri.substring(index + 1); |
608 } else { | 688 } else { |
609 libraryName = dartUri; | 689 libraryName = dartUri; |
610 relativePath = ""; | 690 relativePath = ""; |
611 } | 691 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 769 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
690 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 770 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
691 // If any syntactic errors were found then don't try to visit the AST | 771 // If any syntactic errors were found then don't try to visit the AST |
692 // structure. | 772 // structure. |
693 if (!errorListener.errorReported) { | 773 if (!errorListener.errorReported) { |
694 unit.accept(libraryBuilder); | 774 unit.accept(libraryBuilder); |
695 } | 775 } |
696 return libraryBuilder.librariesMap; | 776 return libraryBuilder.librariesMap; |
697 } | 777 } |
698 } | 778 } |
OLD | NEW |