OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_impl; | 5 library analyzer_impl; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:path/path.dart' as pathos; | |
12 | |
13 import 'generated/constant.dart'; | 11 import 'generated/constant.dart'; |
14 import 'generated/engine.dart'; | 12 import 'generated/engine.dart'; |
15 import 'generated/element.dart'; | 13 import 'generated/element.dart'; |
16 import 'generated/error.dart'; | 14 import 'generated/error.dart'; |
17 import 'generated/java_io.dart'; | 15 import 'generated/java_io.dart'; |
18 import 'generated/sdk.dart'; | 16 import 'generated/sdk.dart'; |
19 import 'generated/sdk_io.dart'; | 17 import 'generated/sdk_io.dart'; |
20 import 'generated/source_io.dart'; | 18 import 'generated/source_io.dart'; |
21 import '../options.dart'; | 19 import '../options.dart'; |
22 | 20 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 /** | 80 /** |
83 * Setup local fields such as the analysis context for analysis. | 81 * Setup local fields such as the analysis context for analysis. |
84 */ | 82 */ |
85 void setupForAnalysis() { | 83 void setupForAnalysis() { |
86 sources.clear(); | 84 sources.clear(); |
87 errorInfos.clear(); | 85 errorInfos.clear(); |
88 if (sourcePath == null) { | 86 if (sourcePath == null) { |
89 throw new ArgumentError("sourcePath cannot be null"); | 87 throw new ArgumentError("sourcePath cannot be null"); |
90 } | 88 } |
91 JavaFile sourceFile = new JavaFile(sourcePath); | 89 JavaFile sourceFile = new JavaFile(sourcePath); |
92 UriKind uriKind = getUriKind(sourceFile); | 90 Uri uri = getUri(sourceFile); |
93 librarySource = new FileBasedSource.con2(sourceFile, uriKind); | 91 librarySource = new FileBasedSource.con2(uri, sourceFile); |
94 | 92 |
95 // prepare context | 93 // prepare context |
96 prepareAnalysisContext(sourceFile, librarySource); | 94 prepareAnalysisContext(sourceFile, librarySource); |
97 } | 95 } |
98 | 96 |
99 /// The sync version of analysis. | 97 /// The sync version of analysis. |
100 ErrorSeverity _analyzeSync(int printMode) { | 98 ErrorSeverity _analyzeSync(int printMode) { |
101 // don't try to analyze parts | 99 // don't try to analyze parts |
102 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 100 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
103 print("Only libraries can be analyzed."); | 101 print("Only libraries can be analyzed."); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 if (packagesDir.exists()) { | 338 if (packagesDir.exists()) { |
341 return packagesDir; | 339 return packagesDir; |
342 } | 340 } |
343 dir = dir.getParentFile(); | 341 dir = dir.getParentFile(); |
344 } | 342 } |
345 // not found | 343 // not found |
346 return null; | 344 return null; |
347 } | 345 } |
348 | 346 |
349 /** | 347 /** |
350 * Returns the [UriKind] for the given input file. Usually {@link UriKind#FILE
_URI}, but if | 348 * Returns the [Uri] for the given input file. |
351 * the given file is located in the "lib" directory of the [sdk], then returns | 349 * |
352 * {@link UriKind#DART_URI}. | 350 * Usually it is a `file:` [Uri], but if [file] is located in the `lib` |
| 351 * directory of the [sdk], then returns a `dart:` [Uri]. |
353 */ | 352 */ |
354 static UriKind getUriKind(JavaFile file) { | 353 static Uri getUri(JavaFile file) { |
355 // may be file in SDK | 354 // may be file in SDK |
356 if (sdk is DirectoryBasedDartSdk) { | 355 { |
357 DirectoryBasedDartSdk directoryBasedSdk = sdk; | 356 Source source = sdk.fromFileUri(file.toURI()); |
358 var libraryDirectory = directoryBasedSdk.libraryDirectory.getAbsolutePath(
); | 357 if (source != null) { |
359 var sdkLibPath = libraryDirectory + pathos.separator; | 358 return source.uri; |
360 var filePath = file.getPath(); | |
361 if (filePath.startsWith(sdkLibPath)) { | |
362 var internalPath = pathos.join(libraryDirectory, '_internal') + pathos.s
eparator; | |
363 if (!filePath.startsWith(internalPath)) { | |
364 return UriKind.DART_URI; | |
365 } | |
366 } | 359 } |
367 } | 360 } |
368 // some generic file | 361 // some generic file |
369 return UriKind.FILE_URI; | 362 return file.toURI(); |
370 } | 363 } |
371 } | 364 } |
372 | 365 |
373 /** | 366 /** |
374 * This [Logger] prints out information comments to [stdout] and error messages | 367 * This [Logger] prints out information comments to [stdout] and error messages |
375 * to [stderr]. | 368 * to [stderr]. |
376 */ | 369 */ |
377 class StdLogger extends Logger { | 370 class StdLogger extends Logger { |
378 final bool log; | 371 final bool log; |
379 | 372 |
(...skipping 16 matching lines...) Expand all Loading... |
396 } | 389 } |
397 } | 390 } |
398 | 391 |
399 @override | 392 @override |
400 void logInformation2(String message, Exception exception) { | 393 void logInformation2(String message, Exception exception) { |
401 if (log) { | 394 if (log) { |
402 stdout.writeln(message); | 395 stdout.writeln(message); |
403 } | 396 } |
404 } | 397 } |
405 } | 398 } |
OLD | NEW |