| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.sdk.io; | 8 library engine.sdk.io; |
| 9 | 9 |
| 10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 * | 223 * |
| 224 * @param sdkDirectory the directory containing the SDK | 224 * @param sdkDirectory the directory containing the SDK |
| 225 * @param useDart2jsPaths `true` if the dart2js path should be used when it is
available | 225 * @param useDart2jsPaths `true` if the dart2js path should be used when it is
available |
| 226 */ | 226 */ |
| 227 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 227 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
| 228 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 228 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
| 229 _libraryMap = initialLibraryMap(useDart2jsPaths); | 229 _libraryMap = initialLibraryMap(useDart2jsPaths); |
| 230 } | 230 } |
| 231 | 231 |
| 232 @override | 232 @override |
| 233 Source fromEncoding(UriKind kind, Uri uri) => new FileBasedSource.con2(new Jav
aFile.fromUri(uri), kind); | 233 Source fromFileUri(Uri uri) { |
| 234 JavaFile file = new JavaFile.fromUri(uri); |
| 235 String filePath = file.getAbsolutePath(); |
| 236 String libPath = libraryDirectory.getAbsolutePath(); |
| 237 if (!filePath.startsWith("${libPath}${JavaFile.separator}")) { |
| 238 return null; |
| 239 } |
| 240 filePath = filePath.substring(libPath.length + 1); |
| 241 for (SdkLibrary library in _libraryMap.sdkLibraries) { |
| 242 String libraryPath = library.path; |
| 243 if (filePath.replaceAll('\\', '/') == libraryPath) { |
| 244 String path = library.shortName; |
| 245 try { |
| 246 return new FileBasedSource.con2(parseUriWithException(path), file); |
| 247 } on URISyntaxException catch (exception) { |
| 248 AnalysisEngine.instance.logger.logInformation2("Failed to create URI:
${path}", exception); |
| 249 return null; |
| 250 } |
| 251 } |
| 252 libraryPath = new JavaFile(libraryPath).getParent(); |
| 253 if (filePath.startsWith("${libraryPath}${JavaFile.separator}")) { |
| 254 String path = "${library.shortName}/${filePath.substring(libraryPath.len
gth + 1)}"; |
| 255 try { |
| 256 return new FileBasedSource.con2(parseUriWithException(path), file); |
| 257 } on URISyntaxException catch (exception) { |
| 258 AnalysisEngine.instance.logger.logInformation2("Failed to create URI:
${path}", exception); |
| 259 return null; |
| 260 } |
| 261 } |
| 262 } |
| 263 return null; |
| 264 } |
| 234 | 265 |
| 235 @override | 266 @override |
| 236 AnalysisContext get context { | 267 AnalysisContext get context { |
| 237 if (_analysisContext == null) { | 268 if (_analysisContext == null) { |
| 238 _analysisContext = new SdkAnalysisContext(); | 269 _analysisContext = new SdkAnalysisContext(); |
| 239 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 270 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 240 _analysisContext.sourceFactory = factory; | 271 _analysisContext.sourceFactory = factory; |
| 241 List<String> uris = this.uris; | 272 List<String> uris = this.uris; |
| 242 ChangeSet changeSet = new ChangeSet(); | 273 ChangeSet changeSet = new ChangeSet(); |
| 243 for (String uri in uris) { | 274 for (String uri in uris) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 443 |
| 413 /** | 444 /** |
| 414 * Return `true` if the Dartium binary is available. | 445 * Return `true` if the Dartium binary is available. |
| 415 * | 446 * |
| 416 * @return `true` if the Dartium binary is available | 447 * @return `true` if the Dartium binary is available |
| 417 */ | 448 */ |
| 418 bool get isDartiumInstalled => dartiumExecutable != null; | 449 bool get isDartiumInstalled => dartiumExecutable != null; |
| 419 | 450 |
| 420 @override | 451 @override |
| 421 Source mapDartUri(String dartUri) { | 452 Source mapDartUri(String dartUri) { |
| 422 SdkLibrary library = getSdkLibrary(dartUri); | 453 String libraryName; |
| 454 String relativePath; |
| 455 int index = dartUri.indexOf('/'); |
| 456 if (index >= 0) { |
| 457 libraryName = dartUri.substring(0, index); |
| 458 relativePath = dartUri.substring(index + 1); |
| 459 } else { |
| 460 libraryName = dartUri; |
| 461 relativePath = ""; |
| 462 } |
| 463 SdkLibrary library = getSdkLibrary(libraryName); |
| 423 if (library == null) { | 464 if (library == null) { |
| 424 return null; | 465 return null; |
| 425 } | 466 } |
| 426 return new FileBasedSource.con2(new JavaFile.relative(libraryDirectory, libr
ary.path), UriKind.DART_URI); | 467 try { |
| 468 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); |
| 469 if (!relativePath.isEmpty) { |
| 470 file = file.getParentFile(); |
| 471 file = new JavaFile.relative(file, relativePath); |
| 472 } |
| 473 return new FileBasedSource.con2(parseUriWithException(dartUri), file); |
| 474 } on URISyntaxException catch (exception) { |
| 475 return null; |
| 476 } |
| 427 } | 477 } |
| 428 | 478 |
| 429 /** | 479 /** |
| 430 * Read all of the configuration files to initialize the library maps. | 480 * Read all of the configuration files to initialize the library maps. |
| 431 * | 481 * |
| 432 * @param useDart2jsPaths `true` if the dart2js path should be used when it is
available | 482 * @param useDart2jsPaths `true` if the dart2js path should be used when it is
available |
| 433 * @return the initialized library map | 483 * @return the initialized library map |
| 434 */ | 484 */ |
| 435 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 485 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 436 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(library
Directory, _INTERNAL_DIR), _LIBRARIES_FILE); | 486 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(library
Directory, _INTERNAL_DIR), _LIBRARIES_FILE); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 */ | 574 */ |
| 525 SdkLibrariesReader(this._useDart2jsPaths); | 575 SdkLibrariesReader(this._useDart2jsPaths); |
| 526 | 576 |
| 527 /** | 577 /** |
| 528 * Return the library map read from the given source. | 578 * Return the library map read from the given source. |
| 529 * | 579 * |
| 530 * @param file the [File] of the library file | 580 * @param file the [File] of the library file |
| 531 * @param libraryFileContents the contents from the library file | 581 * @param libraryFileContents the contents from the library file |
| 532 * @return the library map read from the given source | 582 * @return the library map read from the given source |
| 533 */ | 583 */ |
| 534 LibraryMap readFromFile(JavaFile file, String libraryFileContents) => readFrom
Source(new FileBasedSource.con2(file, UriKind.FILE_URI), libraryFileContents); | 584 LibraryMap readFromFile(JavaFile file, String libraryFileContents) => readFrom
Source(new FileBasedSource.con1(file), libraryFileContents); |
| 535 | 585 |
| 536 /** | 586 /** |
| 537 * Return the library map read from the given source. | 587 * Return the library map read from the given source. |
| 538 * | 588 * |
| 539 * @param source the source of the library file | 589 * @param source the source of the library file |
| 540 * @param libraryFileContents the contents from the library file | 590 * @param libraryFileContents the contents from the library file |
| 541 * @return the library map read from the given source | 591 * @return the library map read from the given source |
| 542 */ | 592 */ |
| 543 LibraryMap readFromSource(Source source, String libraryFileContents) { | 593 LibraryMap readFromSource(Source source, String libraryFileContents) { |
| 544 BooleanErrorListener errorListener = new BooleanErrorListener(); | 594 BooleanErrorListener errorListener = new BooleanErrorListener(); |
| 545 Scanner scanner = new Scanner(source, new CharSequenceReader(libraryFileCont
ents), errorListener); | 595 Scanner scanner = new Scanner(source, new CharSequenceReader(libraryFileCont
ents), errorListener); |
| 546 Parser parser = new Parser(source, errorListener); | 596 Parser parser = new Parser(source, errorListener); |
| 547 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); | 597 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); |
| 548 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li
braryBuilder(_useDart2jsPaths); | 598 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li
braryBuilder(_useDart2jsPaths); |
| 549 // If any syntactic errors were found then don't try to visit the AST struct
ure. | 599 // If any syntactic errors were found then don't try to visit the AST struct
ure. |
| 550 if (!errorListener.errorReported) { | 600 if (!errorListener.errorReported) { |
| 551 unit.accept(libraryBuilder); | 601 unit.accept(libraryBuilder); |
| 552 } | 602 } |
| 553 return libraryBuilder.librariesMap; | 603 return libraryBuilder.librariesMap; |
| 554 } | 604 } |
| 555 } | 605 } |
| OLD | NEW |