| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
| 7 | 7 |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart' | 9 import 'package:analyzer/file_system/file_system.dart' |
| 10 show File, Folder, ResourceProvider, ResourceUriResolver; | 10 show File, Folder, ResourceProvider, ResourceUriResolver; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 AnalysisOptions _buildAnalyzerOptions(DriverOptions options) { | 44 AnalysisOptions _buildAnalyzerOptions(DriverOptions options) { |
| 45 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 45 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 46 analysisOptions.strongMode = options.strongMode; | 46 analysisOptions.strongMode = options.strongMode; |
| 47 analysisOptions.hint = false; | 47 analysisOptions.hint = false; |
| 48 analysisOptions.lint = options.enableLints; | 48 analysisOptions.lint = options.enableLints; |
| 49 analysisOptions.generateSdkErrors = options.showSdkWarnings; | 49 analysisOptions.generateSdkErrors = options.showSdkWarnings; |
| 50 analysisOptions.enableTiming = options.enableTiming; | 50 analysisOptions.enableTiming = options.enableTiming; |
| 51 return analysisOptions; | 51 return analysisOptions; |
| 52 } | 52 } |
| 53 | 53 |
| 54 class AnalysisDriver { | 54 class DriverOptions { |
| 55 /// The maximum number of sources for which AST structures should be kept |
| 56 /// in the cache. The default is 512. |
| 57 int cacheSize = 512; |
| 58 |
| 59 /// The path to the dart SDK. |
| 60 String dartSdkPath; |
| 61 |
| 62 /// Whether to show lint warnings. |
| 63 bool enableLints = true; |
| 64 |
| 65 /// Whether to gather timing data during analysis. |
| 66 bool enableTiming = false; |
| 67 |
| 68 /// The path to a `.packages` configuration file |
| 69 String packageConfigPath; |
| 70 |
| 71 /// The path to the package root. |
| 72 String packageRootPath; |
| 73 |
| 74 /// Whether to show SDK warnings. |
| 75 bool showSdkWarnings = false; |
| 76 |
| 77 /// Whether to use Dart's Strong Mode analyzer. |
| 78 bool strongMode = true; |
| 79 |
| 80 /// The mock SDK (to speed up testing) or `null` to use the actual SDK. |
| 81 DartSdk mockSdk; |
| 82 |
| 83 /// Whether to show lints for the transitive closure of imported and exported |
| 84 /// libraries. |
| 85 bool visitTransitiveClosure = false; |
| 86 } |
| 87 |
| 88 class LintDriver { |
| 55 /// The sources which have been analyzed so far. This is used to avoid | 89 /// The sources which have been analyzed so far. This is used to avoid |
| 56 /// analyzing a source more than once, and to compute the total number of | 90 /// analyzing a source more than once, and to compute the total number of |
| 57 /// sources analyzed for statistics. | 91 /// sources analyzed for statistics. |
| 58 Set<Source> _sourcesAnalyzed = new HashSet<Source>(); | 92 Set<Source> _sourcesAnalyzed = new HashSet<Source>(); |
| 59 | 93 |
| 60 final LinterOptions options; | 94 final LinterOptions options; |
| 61 | 95 |
| 62 AnalysisDriver(this.options) { | 96 LintDriver(this.options) { |
| 63 _processPlugins(); | 97 _processPlugins(); |
| 64 } | 98 } |
| 65 | 99 |
| 66 /// Return the number of sources that have been analyzed so far. | 100 /// Return the number of sources that have been analyzed so far. |
| 67 int get numSourcesAnalyzed => _sourcesAnalyzed.length; | 101 int get numSourcesAnalyzed => _sourcesAnalyzed.length; |
| 68 | 102 |
| 69 List<UriResolver> get resolvers { | 103 List<UriResolver> get resolvers { |
| 70 // TODO(brianwilkerson) Use the context builder to compute all of the resolv
ers. | 104 // TODO(brianwilkerson) Use the context builder to compute all of the resolv
ers. |
| 71 ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; | 105 ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE; |
| 72 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); | 106 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 243 } |
| 210 | 244 |
| 211 void _processPlugins() { | 245 void _processPlugins() { |
| 212 List<Plugin> plugins = <Plugin>[]; | 246 List<Plugin> plugins = <Plugin>[]; |
| 213 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 247 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 214 ExtensionManager manager = new ExtensionManager(); | 248 ExtensionManager manager = new ExtensionManager(); |
| 215 manager.processPlugins(plugins); | 249 manager.processPlugins(plugins); |
| 216 } | 250 } |
| 217 } | 251 } |
| 218 | 252 |
| 219 class DriverOptions { | |
| 220 /// The maximum number of sources for which AST structures should be kept | |
| 221 /// in the cache. The default is 512. | |
| 222 int cacheSize = 512; | |
| 223 | |
| 224 /// The path to the dart SDK. | |
| 225 String dartSdkPath; | |
| 226 | |
| 227 /// Whether to show lint warnings. | |
| 228 bool enableLints = true; | |
| 229 | |
| 230 /// Whether to gather timing data during analysis. | |
| 231 bool enableTiming = false; | |
| 232 | |
| 233 /// The path to a `.packages` configuration file | |
| 234 String packageConfigPath; | |
| 235 | |
| 236 /// The path to the package root. | |
| 237 String packageRootPath; | |
| 238 | |
| 239 /// Whether to show SDK warnings. | |
| 240 bool showSdkWarnings = false; | |
| 241 | |
| 242 /// Whether to use Dart's Strong Mode analyzer. | |
| 243 bool strongMode = true; | |
| 244 | |
| 245 /// The mock SDK (to speed up testing) or `null` to use the actual SDK. | |
| 246 DartSdk mockSdk; | |
| 247 | |
| 248 /// Whether to show lints for the transitive closure of imported and exported | |
| 249 /// libraries. | |
| 250 bool visitTransitiveClosure = false; | |
| 251 } | |
| 252 | |
| 253 /// Prints logging information comments to the [outSink] and error messages to | 253 /// Prints logging information comments to the [outSink] and error messages to |
| 254 /// [errorSink]. | 254 /// [errorSink]. |
| 255 class StdLogger extends Logger { | 255 class StdLogger extends Logger { |
| 256 @override | 256 @override |
| 257 void logError(String message, [exception]) => errorSink.writeln(message); | 257 void logError(String message, [exception]) => errorSink.writeln(message); |
| 258 @override | 258 @override |
| 259 void logInformation(String message, [exception]) => outSink.writeln(message); | 259 void logInformation(String message, [exception]) => outSink.writeln(message); |
| 260 } | 260 } |
| OLD | NEW |