Chromium Code Reviews| 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:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:analyzer/file_system/file_system.dart' show Folder; | 11 import 'package:analyzer/file_system/file_system.dart' show Folder; |
| 12 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 13 import 'package:analyzer/source/package_map_provider.dart'; | 13 import 'package:analyzer/source/package_map_provider.dart'; |
| 14 import 'package:analyzer/source/package_map_resolver.dart'; | 14 import 'package:analyzer/source/package_map_resolver.dart'; |
| 15 import 'package:analyzer/source/pub_package_map_provider.dart'; | 15 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 16 import 'package:analyzer/src/error_formatter.dart'; | 16 import 'package:analyzer/src/error_formatter.dart'; |
| 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; | 17 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; |
| 18 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
| 19 import 'package:analyzer/src/generated/utilities_general.dart'; | |
| 19 | 20 |
| 20 import '../options.dart'; | 21 import '../options.dart'; |
| 21 import 'generated/constant.dart'; | 22 import 'generated/constant.dart'; |
| 22 import 'generated/element.dart'; | 23 import 'generated/element.dart'; |
| 23 import 'generated/engine.dart'; | 24 import 'generated/engine.dart'; |
| 24 import 'generated/error.dart'; | 25 import 'generated/error.dart'; |
| 25 import 'generated/java_io.dart'; | 26 import 'generated/java_io.dart'; |
| 26 import 'generated/sdk_io.dart'; | 27 import 'generated/sdk_io.dart'; |
| 27 import 'generated/source_io.dart'; | 28 import 'generated/source_io.dart'; |
| 28 import 'package:analyzer/src/generated/utilities_general.dart'; | |
| 29 | 29 |
| 30 DirectoryBasedDartSdk sdk; | 30 DirectoryBasedDartSdk sdk; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * The maximum number of sources for which AST structures should be kept in the cache. | 33 * The maximum number of sources for which AST structures should be kept in the cache. |
| 34 */ | 34 */ |
| 35 const int _MAX_CACHE_SIZE = 512; | 35 const int _MAX_CACHE_SIZE = 512; |
| 36 | 36 |
| 37 /// Analyzes single library [File]. | 37 /// Analyzes single library [File]. |
| 38 class AnalyzerImpl { | 38 class AnalyzerImpl { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 packageDirectory = new JavaFile(options.packageRootPath); | 150 packageDirectory = new JavaFile(options.packageRootPath); |
| 151 resolvers.add(new PackageUriResolver([packageDirectory])); | 151 resolvers.add(new PackageUriResolver([packageDirectory])); |
| 152 } else { | 152 } else { |
| 153 PubPackageMapProvider pubPackageMapProvider = | 153 PubPackageMapProvider pubPackageMapProvider = |
| 154 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); | 154 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); |
| 155 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( | 155 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( |
| 156 PhysicalResourceProvider.INSTANCE.getResource('.')); | 156 PhysicalResourceProvider.INSTANCE.getResource('.')); |
| 157 Map<String, List<Folder>> packageMap = packageMapInfo.packageMap; | 157 Map<String, List<Folder>> packageMap = packageMapInfo.packageMap; |
| 158 if (packageMap != null) { | 158 if (packageMap != null) { |
| 159 resolvers.add( | 159 resolvers.add( |
| 160 new PackageMapUriResolver( | 160 new PackageMapUriResolver(PhysicalResourceProvider.INSTANCE, packa geMap)); |
| 161 PhysicalResourceProvider.INSTANCE, | |
| 162 packageMap)); | |
| 163 } | 161 } |
| 164 } | 162 } |
| 165 } | 163 } |
| 166 sourceFactory = new SourceFactory(resolvers); | 164 sourceFactory = new SourceFactory(resolvers); |
| 167 context = AnalysisEngine.instance.createAnalysisContext(); | 165 context = AnalysisEngine.instance.createAnalysisContext(); |
| 168 context.sourceFactory = sourceFactory; | 166 context.sourceFactory = sourceFactory; |
| 169 Map<String, String> definedVariables = options.definedVariables; | 167 Map<String, String> definedVariables = options.definedVariables; |
| 170 if (!definedVariables.isEmpty) { | 168 if (!definedVariables.isEmpty) { |
| 171 DeclaredVariables declaredVariables = context.declaredVariables; | 169 DeclaredVariables declaredVariables = context.declaredVariables; |
| 172 definedVariables.forEach((String variableName, String value) { | 170 definedVariables.forEach((String variableName, String value) { |
| 173 declaredVariables.define(variableName, value); | 171 declaredVariables.define(variableName, value); |
| 174 }); | 172 }); |
| 175 } | 173 } |
| 176 // Uncomment the following to have errors reported on stdout and stderr | 174 // Uncomment the following to have errors reported on stdout and stderr |
| 177 AnalysisEngine.instance.logger = new StdLogger(options.log); | 175 AnalysisEngine.instance.logger = new StdLogger(options.log); |
| 178 | 176 |
| 179 // set options for context | 177 // set options for context |
| 180 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | 178 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); |
| 181 contextOptions.cacheSize = _MAX_CACHE_SIZE; | 179 contextOptions.cacheSize = _MAX_CACHE_SIZE; |
| 182 contextOptions.hint = !options.disableHints; | 180 contextOptions.hint = !options.disableHints; |
| 181 contextOptions.analyzeFunctionBodiesPredicate = | |
| 182 _analyzeFunctionBodiesPredicate; | |
| 183 context.analysisOptions = contextOptions; | 183 context.analysisOptions = contextOptions; |
| 184 | 184 |
| 185 // Create and add a ChangeSet | 185 // Create and add a ChangeSet |
| 186 ChangeSet changeSet = new ChangeSet(); | 186 ChangeSet changeSet = new ChangeSet(); |
| 187 changeSet.addedSource(source); | 187 changeSet.addedSource(source); |
| 188 context.applyChanges(changeSet); | 188 context.applyChanges(changeSet); |
| 189 } | 189 } |
| 190 | 190 |
| 191 /// Fills [errorInfos] using [sources]. | 191 /// Fills [errorInfos] using [sources]. |
| 192 void prepareErrors() { | 192 void prepareErrors() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 ErrorSeverity status = maxErrorSeverity; | 250 ErrorSeverity status = maxErrorSeverity; |
| 251 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 251 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
| 252 status = ErrorSeverity.ERROR; | 252 status = ErrorSeverity.ERROR; |
| 253 } | 253 } |
| 254 exitCode = status.ordinal; | 254 exitCode = status.ordinal; |
| 255 }).catchError((ex, st) { | 255 }).catchError((ex, st) { |
| 256 AnalysisEngine.instance.logger.logError("$ex\n$st"); | 256 AnalysisEngine.instance.logger.logError("$ex\n$st"); |
| 257 }); | 257 }); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool _analyzeFunctionBodiesPredicate(Source source) { | |
| 261 if (source.uri.scheme == 'dart') { | |
| 262 return options.showSdkWarnings; | |
| 263 } | |
| 264 if (source.uri.scheme == 'package') { | |
| 265 return options.showPackageWarnings; | |
| 266 } | |
| 267 return true; | |
|
Brian Wilkerson
2015/02/27 23:52:05
This will need to be extended to account for the c
Paul Berry
2015/03/02 19:09:45
Ok, I've added a TODO.
| |
| 268 } | |
| 269 | |
| 260 /// The sync version of analysis. | 270 /// The sync version of analysis. |
| 261 ErrorSeverity _analyzeSync(int printMode) { | 271 ErrorSeverity _analyzeSync(int printMode) { |
| 262 // don't try to analyze parts | 272 // don't try to analyze parts |
| 263 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 273 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
| 264 print("Only libraries can be analyzed."); | 274 print("Only libraries can be analyzed."); |
| 265 print("$sourcePath is a part and can not be analyzed."); | 275 print("$sourcePath is a part and can not be analyzed."); |
| 266 return ErrorSeverity.ERROR; | 276 return ErrorSeverity.ERROR; |
| 267 } | 277 } |
| 268 // resolve library | 278 // resolve library |
| 269 var libraryElement = context.computeLibraryElement(librarySource); | 279 var libraryElement = context.computeLibraryElement(librarySource); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 441 } |
| 432 } | 442 } |
| 433 | 443 |
| 434 @override | 444 @override |
| 435 void logInformation2(String message, Object exception) { | 445 void logInformation2(String message, Object exception) { |
| 436 if (log) { | 446 if (log) { |
| 437 stdout.writeln(message); | 447 stdout.writeln(message); |
| 438 } | 448 } |
| 439 } | 449 } |
| 440 } | 450 } |
| OLD | NEW |