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

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

Issue 560553002: Use pub list-package-dirs in analyzer command line (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove package_map_provider test from test_all.dart in server package Created 6 years, 3 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
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
9 import 'dart:io'; 8 import 'dart:io';
10 9
11 import 'generated/constant.dart'; 10 import 'generated/constant.dart';
12 import 'generated/engine.dart'; 11 import 'generated/engine.dart';
13 import 'generated/element.dart'; 12 import 'generated/element.dart';
14 import 'generated/error.dart'; 13 import 'generated/error.dart';
15 import 'generated/java_io.dart'; 14 import 'generated/java_io.dart';
16 import 'generated/sdk.dart';
17 import 'generated/sdk_io.dart'; 15 import 'generated/sdk_io.dart';
18 import 'generated/source_io.dart'; 16 import 'generated/source_io.dart';
19 import '../options.dart'; 17 import '../options.dart';
20 18
21 import 'dart:collection'; 19 import 'dart:collection';
22 20
23 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem; 21 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem;
24 import 'package:analyzer/src/error_formatter.dart'; 22 import 'package:analyzer/src/error_formatter.dart';
23 import 'package:analyzer/file_system/physical_file_system.dart';
24 import 'package:analyzer/source/package_map_resolver.dart';
25 import 'package:analyzer/source/package_map_provider.dart';
25 26
26 /** 27 /**
27 * The maximum number of sources for which AST structures should be kept in the cache. 28 * The maximum number of sources for which AST structures should be kept in the cache.
28 */ 29 */
29 const int _MAX_CACHE_SIZE = 512; 30 const int _MAX_CACHE_SIZE = 512;
30 31
31 DartSdk sdk; 32 DirectoryBasedDartSdk sdk;
32 33
33 /// Analyzes single library [File]. 34 /// Analyzes single library [File].
34 class AnalyzerImpl { 35 class AnalyzerImpl {
35 final String sourcePath; 36 final String sourcePath;
36 final CommandLineOptions options; 37 final CommandLineOptions options;
37 final int startTime; 38 final int startTime;
38 39
39 ContentCache contentCache = new ContentCache(); 40 ContentCache contentCache = new ContentCache();
40 SourceFactory sourceFactory; 41 SourceFactory sourceFactory;
41 AnalysisContext context; 42 AnalysisContext context;
42 Source librarySource; 43 Source librarySource;
43 44
44 /// All [Source]s references by the analyzed library. 45 /// All [Source]s references by the analyzed library.
45 final Set<Source> sources = new Set<Source>(); 46 final Set<Source> sources = new Set<Source>();
46 47
47 /// All [AnalysisErrorInfo]s in the analyzed library. 48 /// All [AnalysisErrorInfo]s in the analyzed library.
48 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); 49 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>();
49 50
50 /// [HashMap] between sources and analysis error infos. 51 /// [HashMap] between sources and analysis error infos.
51 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = new HashMap<Source, AnalysisErrorInfo>(); 52 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap =
53 new HashMap<Source, AnalysisErrorInfo>();
52 54
53 AnalyzerImpl(this.sourcePath, this.options, this.startTime) { 55 AnalyzerImpl(this.sourcePath, this.options, this.startTime) {
54 if (sdk == null) { 56 if (sdk == null) {
55 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); 57 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath));
56 } 58 }
57 } 59 }
58 60
59 /** 61 /**
60 * Treats the [sourcePath] as the top level library and analyzes it using a 62 * Treats the [sourcePath] as the top level library and analyzes it using a
61 * synchronous algorithm over the analysis engine. If [printMode] is `0`, 63 * synchronous algorithm over the analysis engine. If [printMode] is `0`,
62 * then no error or performance information is printed. If [printMode] is `1`, 64 * then no error or performance information is printed. If [printMode] is `1`,
63 * then both will be printed. If [printMode] is `2`, then only performance 65 * then both will be printed. If [printMode] is `2`, then only performance
64 * information will be printed, and it will be marked as being for a cold VM. 66 * information will be printed, and it will be marked as being for a cold VM.
65 */ 67 */
66 ErrorSeverity analyzeSync({int printMode : 1}) { 68 ErrorSeverity analyzeSync({int printMode: 1}) {
67 setupForAnalysis(); 69 setupForAnalysis();
68 return _analyzeSync(printMode); 70 return _analyzeSync(printMode);
69 } 71 }
70 72
71 /** 73 /**
72 * Treats the [sourcePath] as the top level library and analyzes it using a 74 * Treats the [sourcePath] as the top level library and analyzes it using a
73 * asynchronous algorithm over the analysis engine. 75 * asynchronous algorithm over the analysis engine.
74 */ 76 */
75 void analyzeAsync() { 77 void analyzeAsync() {
76 setupForAnalysis(); 78 setupForAnalysis();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 sources.add(notice.source); 136 sources.add(notice.source);
135 sourceErrorsMap[notice.source] = notice; 137 sourceErrorsMap[notice.source] = notice;
136 } 138 }
137 return _analyzeAsync(); 139 return _analyzeAsync();
138 } 140 }
139 // 141 //
140 // There are not any more tasks, set error code and print performance 142 // There are not any more tasks, set error code and print performance
141 // numbers. 143 // numbers.
142 // 144 //
143 // prepare errors 145 // prepare errors
144 sourceErrorsMap.forEach((k,v) { 146 sourceErrorsMap.forEach((k, v) {
145 errorInfos.add(sourceErrorsMap[k]); 147 errorInfos.add(sourceErrorsMap[k]);
146 }); 148 });
147 149
148 // print errors and performance numbers 150 // print errors and performance numbers
149 _printErrorsAndPerf(); 151 _printErrorsAndPerf();
150 152
151 // compute max severity and set exitCode 153 // compute max severity and set exitCode
152 ErrorSeverity status = maxErrorSeverity; 154 ErrorSeverity status = maxErrorSeverity;
153 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { 155 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) {
154 status = ErrorSeverity.ERROR; 156 status = ErrorSeverity.ERROR;
155 } 157 }
156 exitCode = status.ordinal; 158 exitCode = status.ordinal;
157 }).catchError((ex, st) { 159 }).catchError((ex, st) {
158 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); 160 AnalysisEngine.instance.logger.logError("${ex}\n${st}");
159 }); 161 });
160 } 162 }
161 163
162 bool _excludeTodo(AnalysisError error) => error.errorCode.type != ErrorType.TO DO; 164 bool _excludeTodo(AnalysisError error) =>
165 error.errorCode.type != ErrorType.TODO;
163 166
164 _printErrorsAndPerf() { 167 _printErrorsAndPerf() {
165 // The following is a hack. We currently print out to stderr to ensure that 168 // The following is a hack. We currently print out to stderr to ensure that
166 // when in batch mode we print to stderr, this is because the prints from 169 // when in batch mode we print to stderr, this is because the prints from
167 // batch are made to stderr. The reason that options.shouldBatch isn't used 170 // batch are made to stderr. The reason that options.shouldBatch isn't used
168 // is because when the argument flags are constructed in BatchRunner and 171 // is because when the argument flags are constructed in BatchRunner and
169 // passed in from batch mode which removes the batch flag to prevent the 172 // passed in from batch mode which removes the batch flag to prevent the
170 // "cannot have the batch flag and source file" error message. 173 // "cannot have the batch flag and source file" error message.
171 IOSink sink = options.machineFormat ? stderr : stdout; 174 IOSink sink = options.machineFormat ? stderr : stdout;
172 175
(...skipping 15 matching lines...) Expand all
188 stdout.writeln("scan:$scanTime"); 191 stdout.writeln("scan:$scanTime");
189 stdout.writeln("parse:$parseTime"); 192 stdout.writeln("parse:$parseTime");
190 stdout.writeln("resolve:$resolveTime"); 193 stdout.writeln("resolve:$resolveTime");
191 stdout.writeln("errors:$errorsTime"); 194 stdout.writeln("errors:$errorsTime");
192 stdout.writeln("hints:$hintsTime"); 195 stdout.writeln("hints:$hintsTime");
193 stdout.writeln("angular:$angularTime"); 196 stdout.writeln("angular:$angularTime");
194 stdout.writeln("other:${totalTime 197 stdout.writeln("other:${totalTime
195 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTim e 198 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTim e
196 + angularTime)}"); 199 + angularTime)}");
197 stdout.writeln("total:$totalTime"); 200 stdout.writeln("total:$totalTime");
198 } 201 }
199 } 202 }
200 203
201 _printColdPerf() { 204 _printColdPerf() {
202 // print cold VM performance numbers 205 // print cold VM performance numbers
203 int totalTime = JavaSystem.currentTimeMillis() - startTime; 206 int totalTime = JavaSystem.currentTimeMillis() - startTime;
204 int ioTime = PerformanceStatistics.io.result; 207 int ioTime = PerformanceStatistics.io.result;
205 int scanTime = PerformanceStatistics.scan.result; 208 int scanTime = PerformanceStatistics.scan.result;
206 int parseTime = PerformanceStatistics.parse.result; 209 int parseTime = PerformanceStatistics.parse.result;
207 int resolveTime = PerformanceStatistics.resolve.result; 210 int resolveTime = PerformanceStatistics.resolve.result;
208 int errorsTime = PerformanceStatistics.errors.result; 211 int errorsTime = PerformanceStatistics.errors.result;
(...skipping 18 matching lines...) Expand all
227 for (AnalysisErrorInfo errorInfo in errorInfos) { 230 for (AnalysisErrorInfo errorInfo in errorInfos) {
228 for (AnalysisError error in errorInfo.errors) { 231 for (AnalysisError error in errorInfo.errors) {
229 var severity = error.errorCode.errorSeverity; 232 var severity = error.errorCode.errorSeverity;
230 status = status.max(severity); 233 status = status.max(severity);
231 } 234 }
232 } 235 }
233 return status; 236 return status;
234 } 237 }
235 238
236 void prepareAnalysisContext(JavaFile sourceFile, Source source) { 239 void prepareAnalysisContext(JavaFile sourceFile, Source source) {
237 List<UriResolver> resolvers = [new DartUriResolver(sdk), new FileUriResolver ()]; 240 List<UriResolver> resolvers = [
241 new DartUriResolver(sdk),
242 new FileUriResolver()];
238 // may be add package resolver 243 // may be add package resolver
239 { 244 {
240 JavaFile packageDirectory; 245 JavaFile packageDirectory;
241 if (options.packageRootPath != null) { 246 if (options.packageRootPath != null) {
242 packageDirectory = new JavaFile(options.packageRootPath); 247 packageDirectory = new JavaFile(options.packageRootPath);
248 resolvers.add(new PackageUriResolver([packageDirectory]));
249 stdout.write(
Brian Wilkerson 2014/09/09 20:30:43 While it's nice to let users known about the chang
jwren 2014/09/09 20:36:17 Done.
250 "The flag package-root is deprecated, by not including it on the com mand line a call will be made to pub to compute the package information.");
Paul Berry 2014/09/09 20:20:27 This error message is confusing to me. The phrase
jwren 2014/09/09 20:36:17 Done.
243 } else { 251 } else {
244 packageDirectory = getPackageDirectoryFor(sourceFile); 252 PubPackageMapProvider pubPackageMapProvider =
245 } 253 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk);
246 if (packageDirectory != null) { 254 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap(
247 resolvers.add(new PackageUriResolver([packageDirectory])); 255 PhysicalResourceProvider.INSTANCE.getResource(''));
256 resolvers.add(
257 new PackageMapUriResolver(
258 PhysicalResourceProvider.INSTANCE,
259 packageMapInfo.packageMap));
248 } 260 }
249 } 261 }
250 sourceFactory = new SourceFactory(resolvers); 262 sourceFactory = new SourceFactory(resolvers);
251 context = AnalysisEngine.instance.createAnalysisContext(); 263 context = AnalysisEngine.instance.createAnalysisContext();
252 context.sourceFactory = sourceFactory; 264 context.sourceFactory = sourceFactory;
253 Map<String, String> definedVariables = options.definedVariables; 265 Map<String, String> definedVariables = options.definedVariables;
254 if (!definedVariables.isEmpty) { 266 if (!definedVariables.isEmpty) {
255 DeclaredVariables declaredVariables = context.declaredVariables; 267 DeclaredVariables declaredVariables = context.declaredVariables;
256 definedVariables.forEach((String variableName, String value) { 268 definedVariables.forEach((String variableName, String value) {
257 declaredVariables.define(variableName, value); 269 declaredVariables.define(variableName, value);
258 }); 270 });
259 } 271 }
260 // Uncomment the following to have errors reported on stdout and stderr 272 // Uncomment the following to have errors reported on stdout and stderr
261 AnalysisEngine.instance.logger = new StdLogger(options.log); 273 AnalysisEngine.instance.logger = new StdLogger(options.log);
262 274
263 // set options for context 275 // set options for context
264 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); 276 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl();
265 contextOptions.cacheSize = _MAX_CACHE_SIZE; 277 contextOptions.cacheSize = _MAX_CACHE_SIZE;
266 contextOptions.hint = !options.disableHints; 278 contextOptions.hint = !options.disableHints;
267 contextOptions.enableAsync = options.enableAsync; 279 contextOptions.enableAsync = options.enableAsync;
268 contextOptions.enableEnum = options.enableEnum; 280 contextOptions.enableEnum = options.enableEnum;
269 context.analysisOptions = contextOptions; 281 context.analysisOptions = contextOptions;
270 282
271 // Create and add a ChangeSet 283 // Create and add a ChangeSet
272 ChangeSet changeSet = new ChangeSet(); 284 ChangeSet changeSet = new ChangeSet();
273 changeSet.addedSource(source); 285 changeSet.addedSource(source);
274 context.applyChanges(changeSet); 286 context.applyChanges(changeSet);
275 } 287 }
276 288
277 void addCompilationUnitSource(CompilationUnitElement unit, Set<LibraryElement> libraries, 289 void addCompilationUnitSource(CompilationUnitElement unit,
278 Set<CompilationUnitElement> units) { 290 Set<LibraryElement> libraries, Set<CompilationUnitElement> units) {
279 if (unit == null || units.contains(unit)) { 291 if (unit == null || units.contains(unit)) {
280 return; 292 return;
281 } 293 }
282 units.add(unit); 294 units.add(unit);
283 sources.add(unit.source); 295 sources.add(unit.source);
284 } 296 }
285 297
286 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries, 298 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries,
287 Set<CompilationUnitElement> units) { 299 Set<CompilationUnitElement> units) {
288 if (library == null || !libraries.add(library) ) { 300 if (library == null || !libraries.add(library)) {
289 return; 301 return;
290 } 302 }
291 // may be skip library 303 // may be skip library
292 { 304 {
293 UriKind uriKind = library.source.uriKind; 305 UriKind uriKind = library.source.uriKind;
294 // Optionally skip package: libraries. 306 // Optionally skip package: libraries.
295 if (!options.showPackageWarnings && uriKind == UriKind.PACKAGE_URI) { 307 if (!options.showPackageWarnings && uriKind == UriKind.PACKAGE_URI) {
296 return; 308 return;
297 } 309 }
298 // Optionally skip SDK libraries. 310 // Optionally skip SDK libraries.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 403 }
392 } 404 }
393 405
394 @override 406 @override
395 void logInformation2(String message, Exception exception) { 407 void logInformation2(String message, Exception exception) {
396 if (log) { 408 if (log) {
397 stdout.writeln(message); 409 stdout.writeln(message);
398 } 410 }
399 } 411 }
400 } 412 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/source/package_map_provider.dart ('k') | pkg/analyzer/test/source/package_map_provider_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698