Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: pkg/analyzer/lib/src/generated/sdk_io.dart

Issue 1296033004: Support older SDKs in analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 engine.sdk.io; 5 library engine.sdk.io;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/java_engine.dart'; 10 import 'package:analyzer/src/generated/java_engine.dart';
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 */ 332 */
333 JavaFile get libraryDirectory => 333 JavaFile get libraryDirectory =>
334 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); 334 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME);
335 335
336 /** 336 /**
337 * Return the file containing the Pub executable, or `null` if it does not exi st. 337 * Return the file containing the Pub executable, or `null` if it does not exi st.
338 */ 338 */
339 JavaFile get pubExecutable { 339 JavaFile get pubExecutable {
340 if (_pubExecutable == null) { 340 if (_pubExecutable == null) {
341 _pubExecutable = _verifyExecutable(new JavaFile.relative( 341 _pubExecutable = _verifyExecutable(new JavaFile.relative(
342 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities 342 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME),
343 .isWindows() ? _PUB_EXECUTABLE_NAME_WIN : _PUB_EXECUTABLE_NAME)); 343 OSUtilities.isWindows()
344 ? _PUB_EXECUTABLE_NAME_WIN
345 : _PUB_EXECUTABLE_NAME));
344 } 346 }
345 return _pubExecutable; 347 return _pubExecutable;
346 } 348 }
347 349
348 @override 350 @override
349 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; 351 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries;
350 352
351 /** 353 /**
352 * Return the revision number of this SDK, or `"0"` if the revision number 354 * Return the revision number of this SDK, or `"0"` if the revision number
353 * cannot be discovered. 355 * cannot be discovered.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 */ 392 */
391 JavaFile get vmExecutable { 393 JavaFile get vmExecutable {
392 if (_vmExecutable == null) { 394 if (_vmExecutable == null) {
393 _vmExecutable = _verifyExecutable(new JavaFile.relative( 395 _vmExecutable = _verifyExecutable(new JavaFile.relative(
394 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), 396 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME),
395 vmBinaryName)); 397 vmBinaryName));
396 } 398 }
397 return _vmExecutable; 399 return _vmExecutable;
398 } 400 }
399 401
402 /**
403 * Determine the search order for trying to locate the [_LIBRARIES_FILE].
404 */
405 Iterable<JavaFile> get _libraryMapLocations sync* {
406 yield new JavaFile.relative(
407 new JavaFile.relative(
408 new JavaFile.relative(
409 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR),
410 _SDK_LIBRARY_METADATA_DIR),
411 _SDK_LIBRARY_METADATA_LIB_DIR),
412 _LIBRARIES_FILE);
413 yield new JavaFile.relative(
414 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR),
415 _LIBRARIES_FILE);
416 }
417
400 @override 418 @override
401 Source fromFileUri(Uri uri) { 419 Source fromFileUri(Uri uri) {
402 JavaFile file = new JavaFile.fromUri(uri); 420 JavaFile file = new JavaFile.fromUri(uri);
403 String filePath = file.getAbsolutePath(); 421 String filePath = file.getAbsolutePath();
404 String libPath = libraryDirectory.getAbsolutePath(); 422 String libPath = libraryDirectory.getAbsolutePath();
405 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { 423 if (!filePath.startsWith("$libPath${JavaFile.separator}")) {
406 return null; 424 return null;
407 } 425 }
408 filePath = filePath.substring(libPath.length + 1); 426 filePath = filePath.substring(libPath.length + 1);
409 for (SdkLibrary library in _libraryMap.sdkLibraries) { 427 for (SdkLibrary library in _libraryMap.sdkLibraries) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 482
465 @override 483 @override
466 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); 484 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri);
467 485
468 /** 486 /**
469 * Read all of the configuration files to initialize the library maps. The 487 * Read all of the configuration files to initialize the library maps. The
470 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it 488 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it
471 * is available. Return the initialized library map. 489 * is available. Return the initialized library map.
472 */ 490 */
473 LibraryMap initialLibraryMap(bool useDart2jsPaths) { 491 LibraryMap initialLibraryMap(bool useDart2jsPaths) {
474 JavaFile librariesFile = new JavaFile.relative( 492 List<String> searchedPaths = <String>[];
475 new JavaFile.relative( 493 var lastStackTrace = null;
476 new JavaFile.relative( 494 var lastException = null;
477 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), 495 for (JavaFile librariesFile in _libraryMapLocations) {
478 _SDK_LIBRARY_METADATA_DIR), 496 try {
479 _SDK_LIBRARY_METADATA_LIB_DIR), 497 String contents = librariesFile.readAsStringSync();
480 _LIBRARIES_FILE); 498 return new SdkLibrariesReader(useDart2jsPaths)
481 try { 499 .readFromFile(librariesFile, contents);
482 String contents = librariesFile.readAsStringSync(); 500 } catch (exception, stackTrace) {
483 return new SdkLibrariesReader(useDart2jsPaths).readFromFile( 501 searchedPaths.add(librariesFile.getAbsolutePath());
484 librariesFile, contents); 502 lastException = exception;
485 } catch (exception, stackTrace) { 503 lastStackTrace = stackTrace;
486 AnalysisEngine.instance.logger.logError( 504 }
487 "Could not initialize the library map from ${librariesFile.getAbsolute Path()}",
488 new CaughtException(exception, stackTrace));
489 return new LibraryMap();
490 } 505 }
506 AnalysisEngine.instance.logger.logError(
507 "Could not initialize the library map from $searchedPaths",
508 new CaughtException(lastException, lastStackTrace));
509 return new LibraryMap();
491 } 510 }
492 511
493 @override 512 @override
494 Source mapDartUri(String dartUri) { 513 Source mapDartUri(String dartUri) {
495 String libraryName; 514 String libraryName;
496 String relativePath; 515 String relativePath;
497 int index = dartUri.indexOf('/'); 516 int index = dartUri.indexOf('/');
498 if (index >= 0) { 517 if (index >= 0) {
499 libraryName = dartUri.substring(0, index); 518 libraryName = dartUri.substring(0, index);
500 relativePath = dartUri.substring(index + 1); 519 relativePath = dartUri.substring(index + 1);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 SdkLibrariesReader_LibraryBuilder libraryBuilder = 601 SdkLibrariesReader_LibraryBuilder libraryBuilder =
583 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); 602 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths);
584 // If any syntactic errors were found then don't try to visit the AST 603 // If any syntactic errors were found then don't try to visit the AST
585 // structure. 604 // structure.
586 if (!errorListener.errorReported) { 605 if (!errorListener.errorReported) {
587 unit.accept(libraryBuilder); 606 unit.accept(libraryBuilder);
588 } 607 }
589 return libraryBuilder.librariesMap; 608 return libraryBuilder.librariesMap;
590 } 609 }
591 } 610 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698