Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: pkg/analyzer/lib/src/analyzer_impl.dart

Issue 967703002: Avoid unnecessary parsing/resolution when running command line analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address code review comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // TODO(paulberry): This function will need to be updated when we add the
262 // ability to suppress errors, warnings, and hints for files reached via
263 // custom URI's using the "--url-mapping" flag.
264 if (source.uri.scheme == 'dart') {
265 return options.showSdkWarnings;
266 }
267 if (source.uri.scheme == 'package') {
268 return options.showPackageWarnings;
269 }
270 return true;
271 }
272
260 /// The sync version of analysis. 273 /// The sync version of analysis.
261 ErrorSeverity _analyzeSync(int printMode) { 274 ErrorSeverity _analyzeSync(int printMode) {
262 // don't try to analyze parts 275 // don't try to analyze parts
263 if (context.computeKindOf(librarySource) == SourceKind.PART) { 276 if (context.computeKindOf(librarySource) == SourceKind.PART) {
264 print("Only libraries can be analyzed."); 277 print("Only libraries can be analyzed.");
265 print("$sourcePath is a part and can not be analyzed."); 278 print("$sourcePath is a part and can not be analyzed.");
266 return ErrorSeverity.ERROR; 279 return ErrorSeverity.ERROR;
267 } 280 }
268 // resolve library 281 // resolve library
269 var libraryElement = context.computeLibraryElement(librarySource); 282 var libraryElement = context.computeLibraryElement(librarySource);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 444 }
432 } 445 }
433 446
434 @override 447 @override
435 void logInformation2(String message, Object exception) { 448 void logInformation2(String message, Object exception) {
436 if (log) { 449 if (log) {
437 stdout.writeln(message); 450 stdout.writeln(message);
438 } 451 }
439 } 452 }
440 } 453 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698