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/java_io.dart'; | 10 import 'generated/java_io.dart'; |
11 import 'generated/engine.dart'; | 11 import 'generated/engine.dart'; |
12 import 'generated/error.dart'; | 12 import 'generated/error.dart'; |
13 import 'generated/source_io.dart'; | 13 import 'generated/source_io.dart'; |
14 import 'generated/sdk.dart'; | 14 import 'generated/sdk.dart'; |
15 import 'generated/sdk_io.dart'; | 15 import 'generated/sdk_io.dart'; |
16 import 'generated/ast.dart'; | 16 import 'generated/ast.dart'; |
17 import 'generated/element.dart'; | 17 import 'generated/element.dart'; |
18 import '../options.dart'; | 18 import '../options.dart'; |
19 | 19 |
| 20 |
| 21 DartSdk sdk; |
| 22 |
20 /// Analyzes single library [File]. | 23 /// Analyzes single library [File]. |
21 class AnalyzerImpl { | 24 class AnalyzerImpl { |
22 final CommandLineOptions options; | 25 final CommandLineOptions options; |
23 DartSdk sdk; | |
24 | 26 |
25 ContentCache contentCache = new ContentCache(); | 27 ContentCache contentCache = new ContentCache(); |
26 SourceFactory sourceFactory; | 28 SourceFactory sourceFactory; |
27 AnalysisContext context; | 29 AnalysisContext context; |
28 | 30 |
29 /// All [Source]s references by the analyzed library. | 31 /// All [Source]s references by the analyzed library. |
30 final Set<Source> sources = new Set<Source>(); | 32 final Set<Source> sources = new Set<Source>(); |
31 | 33 |
32 /// All [AnalysisErrorInfo]s in the analyzed library. | 34 /// All [AnalysisErrorInfo]s in the analyzed library. |
33 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); | 35 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); |
34 | 36 |
35 AnalyzerImpl(CommandLineOptions this.options) { | 37 AnalyzerImpl(CommandLineOptions this.options) { |
36 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); | 38 if (sdk == null) { |
| 39 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
| 40 } |
37 } | 41 } |
38 | 42 |
39 /** | 43 /** |
40 * Treats the [sourcePath] as the top level library and analyzes it. | 44 * Treats the [sourcePath] as the top level library and analyzes it. |
41 */ | 45 */ |
42 void analyze(String sourcePath) { | 46 void analyze(String sourcePath) { |
43 sources.clear(); | 47 sources.clear(); |
44 errorInfos.clear(); | 48 errorInfos.clear(); |
45 if (sourcePath == null) { | 49 if (sourcePath == null) { |
46 throw new ArgumentError("sourcePath cannot be null"); | 50 throw new ArgumentError("sourcePath cannot be null"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); | 155 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); |
152 if (packagesDir.exists()) { | 156 if (packagesDir.exists()) { |
153 return packagesDir; | 157 return packagesDir; |
154 } | 158 } |
155 dir = dir.getParentFile(); | 159 dir = dir.getParentFile(); |
156 } | 160 } |
157 // not found | 161 // not found |
158 return null; | 162 return null; |
159 } | 163 } |
160 } | 164 } |
OLD | NEW |