| 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 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'generated/constant.dart'; | 10 import 'generated/constant.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 /// All [Source]s references by the analyzed library. | 61 /// All [Source]s references by the analyzed library. |
| 62 final Set<Source> sources = new Set<Source>(); | 62 final Set<Source> sources = new Set<Source>(); |
| 63 | 63 |
| 64 /// All [AnalysisErrorInfo]s in the analyzed library. | 64 /// All [AnalysisErrorInfo]s in the analyzed library. |
| 65 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); | 65 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); |
| 66 | 66 |
| 67 /// [HashMap] between sources and analysis error infos. | 67 /// [HashMap] between sources and analysis error infos. |
| 68 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = | 68 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = |
| 69 new HashMap<Source, AnalysisErrorInfo>(); | 69 new HashMap<Source, AnalysisErrorInfo>(); |
| 70 | 70 |
| 71 AnalyzerImpl(this.sourcePath, this.options, this.startTime) { | 71 AnalyzerImpl(String sourcePath, this.options, this.startTime) |
| 72 : sourcePath = _normalizeSourcePath(sourcePath) { |
| 72 if (sdk == null) { | 73 if (sdk == null) { |
| 73 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); | 74 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 /** | 78 /** |
| 78 * Treats the [sourcePath] as the top level library and analyzes it using a | 79 * Treats the [sourcePath] as the top level library and analyzes it using a |
| 79 * synchronous algorithm over the analysis engine. If [printMode] is `0`, | 80 * synchronous algorithm over the analysis engine. If [printMode] is `0`, |
| 80 * then no error or performance information is printed. If [printMode] is `1`, | 81 * then no error or performance information is printed. If [printMode] is `1`, |
| 81 * then both will be printed. If [printMode] is `2`, then only performance | 82 * then both will be printed. If [printMode] is `2`, then only performance |
| (...skipping 23 matching lines...) Expand all Loading... |
| 105 throw new ArgumentError("sourcePath cannot be null"); | 106 throw new ArgumentError("sourcePath cannot be null"); |
| 106 } | 107 } |
| 107 JavaFile sourceFile = new JavaFile(sourcePath); | 108 JavaFile sourceFile = new JavaFile(sourcePath); |
| 108 Uri uri = getUri(sourceFile); | 109 Uri uri = getUri(sourceFile); |
| 109 librarySource = new FileBasedSource.con2(uri, sourceFile); | 110 librarySource = new FileBasedSource.con2(uri, sourceFile); |
| 110 | 111 |
| 111 // prepare context | 112 // prepare context |
| 112 prepareAnalysisContext(sourceFile, librarySource); | 113 prepareAnalysisContext(sourceFile, librarySource); |
| 113 } | 114 } |
| 114 | 115 |
| 116 /** |
| 117 * Convert [sourcePath] into an absolute path. |
| 118 */ |
| 119 static String _normalizeSourcePath(String sourcePath) { |
| 120 return new File(sourcePath).absolute.path; |
| 121 } |
| 122 |
| 115 /// The sync version of analysis. | 123 /// The sync version of analysis. |
| 116 ErrorSeverity _analyzeSync(int printMode) { | 124 ErrorSeverity _analyzeSync(int printMode) { |
| 117 // don't try to analyze parts | 125 // don't try to analyze parts |
| 118 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 126 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
| 119 print("Only libraries can be analyzed."); | 127 print("Only libraries can be analyzed."); |
| 120 print("$sourcePath is a part and can not be analyzed."); | 128 print("$sourcePath is a part and can not be analyzed."); |
| 121 return ErrorSeverity.ERROR; | 129 return ErrorSeverity.ERROR; |
| 122 } | 130 } |
| 123 // resolve library | 131 // resolve library |
| 124 var libraryElement = context.computeLibraryElement(librarySource); | 132 var libraryElement = context.computeLibraryElement(librarySource); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 442 } |
| 435 } | 443 } |
| 436 | 444 |
| 437 @override | 445 @override |
| 438 void logInformation2(String message, Object exception) { | 446 void logInformation2(String message, Object exception) { |
| 439 if (log) { | 447 if (log) { |
| 440 stdout.writeln(message); | 448 stdout.writeln(message); |
| 441 } | 449 } |
| 442 } | 450 } |
| 443 } | 451 } |
| OLD | NEW |