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 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * then both will be printed. If [printMode] is `2`, then only performance | 133 * then both will be printed. If [printMode] is `2`, then only performance |
134 * information will be printed, and it will be marked as being for a cold VM. | 134 * information will be printed, and it will be marked as being for a cold VM. |
135 */ | 135 */ |
136 ErrorSeverity analyzeSync({int printMode: 1}) { | 136 ErrorSeverity analyzeSync({int printMode: 1}) { |
137 setupForAnalysis(); | 137 setupForAnalysis(); |
138 return _analyzeSync(printMode); | 138 return _analyzeSync(printMode); |
139 } | 139 } |
140 | 140 |
141 void prepareAnalysisContext(JavaFile sourceFile, Source source) { | 141 void prepareAnalysisContext(JavaFile sourceFile, Source source) { |
142 List<UriResolver> resolvers = [ | 142 List<UriResolver> resolvers = [ |
143 new CustomUriResolver(options.customUrlMappings), | 143 new CustomUriResolver(options.customUrlMappings), |
144 new DartUriResolver(sdk), | 144 new DartUriResolver(sdk), |
145 new FileUriResolver()]; | 145 new FileUriResolver() |
| 146 ]; |
146 // may be add package resolver | 147 // may be add package resolver |
147 { | 148 { |
148 JavaFile packageDirectory; | 149 JavaFile packageDirectory; |
149 if (options.packageRootPath != null) { | 150 if (options.packageRootPath != null) { |
150 packageDirectory = new JavaFile(options.packageRootPath); | 151 packageDirectory = new JavaFile(options.packageRootPath); |
151 resolvers.add(new PackageUriResolver([packageDirectory])); | 152 resolvers.add(new PackageUriResolver([packageDirectory])); |
152 } else { | 153 } else { |
153 PubPackageMapProvider pubPackageMapProvider = | 154 PubPackageMapProvider pubPackageMapProvider = |
154 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); | 155 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); |
155 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( | 156 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( |
156 PhysicalResourceProvider.INSTANCE.getResource('.')); | 157 PhysicalResourceProvider.INSTANCE.getResource('.')); |
157 Map<String, List<Folder>> packageMap = packageMapInfo.packageMap; | 158 Map<String, List<Folder>> packageMap = packageMapInfo.packageMap; |
158 if (packageMap != null) { | 159 if (packageMap != null) { |
159 resolvers.add( | 160 resolvers.add(new PackageMapUriResolver( |
160 new PackageMapUriResolver(PhysicalResourceProvider.INSTANCE, packa
geMap)); | 161 PhysicalResourceProvider.INSTANCE, packageMap)); |
161 } | 162 } |
162 } | 163 } |
163 } | 164 } |
164 sourceFactory = new SourceFactory(resolvers); | 165 sourceFactory = new SourceFactory(resolvers); |
165 context = AnalysisEngine.instance.createAnalysisContext(); | 166 context = AnalysisEngine.instance.createAnalysisContext(); |
166 context.sourceFactory = sourceFactory; | 167 context.sourceFactory = sourceFactory; |
167 Map<String, String> definedVariables = options.definedVariables; | 168 Map<String, String> definedVariables = options.definedVariables; |
168 if (!definedVariables.isEmpty) { | 169 if (!definedVariables.isEmpty) { |
169 DeclaredVariables declaredVariables = context.declaredVariables; | 170 DeclaredVariables declaredVariables = context.declaredVariables; |
170 definedVariables.forEach((String variableName, String value) { | 171 definedVariables.forEach((String variableName, String value) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 status = ErrorSeverity.ERROR; | 298 status = ErrorSeverity.ERROR; |
298 } | 299 } |
299 return status; | 300 return status; |
300 } | 301 } |
301 | 302 |
302 bool _isDesiredError(AnalysisError error) { | 303 bool _isDesiredError(AnalysisError error) { |
303 if (error.errorCode.type == ErrorType.TODO) { | 304 if (error.errorCode.type == ErrorType.TODO) { |
304 return false; | 305 return false; |
305 } | 306 } |
306 if (computeSeverity(error, options.enableTypeChecks) == | 307 if (computeSeverity(error, options.enableTypeChecks) == |
307 ErrorSeverity.INFO && | 308 ErrorSeverity.INFO && |
308 options.disableHints) { | 309 options.disableHints) { |
309 return false; | 310 return false; |
310 } | 311 } |
311 return true; | 312 return true; |
312 } | 313 } |
313 | 314 |
314 _printColdPerf() { | 315 _printColdPerf() { |
315 // print cold VM performance numbers | 316 // print cold VM performance numbers |
316 int totalTime = JavaSystem.currentTimeMillis() - startTime; | 317 int totalTime = JavaSystem.currentTimeMillis() - startTime; |
317 int otherTime = totalTime; | 318 int otherTime = totalTime; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 stdout.writeln('other:$otherTime'); | 355 stdout.writeln('other:$otherTime'); |
355 stdout.writeln("total:$totalTime"); | 356 stdout.writeln("total:$totalTime"); |
356 } | 357 } |
357 } | 358 } |
358 | 359 |
359 /** | 360 /** |
360 * Compute the severity of the error; however, if | 361 * Compute the severity of the error; however, if |
361 * [enableTypeChecks] is false, then de-escalate checked-mode compile time | 362 * [enableTypeChecks] is false, then de-escalate checked-mode compile time |
362 * errors to a severity of [ErrorSeverity.INFO]. | 363 * errors to a severity of [ErrorSeverity.INFO]. |
363 */ | 364 */ |
364 static ErrorSeverity computeSeverity(AnalysisError error, | 365 static ErrorSeverity computeSeverity( |
365 bool enableTypeChecks) { | 366 AnalysisError error, bool enableTypeChecks) { |
366 if (!enableTypeChecks && | 367 if (!enableTypeChecks && |
367 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { | 368 error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) { |
368 return ErrorSeverity.INFO; | 369 return ErrorSeverity.INFO; |
369 } | 370 } |
370 return error.errorCode.errorSeverity; | 371 return error.errorCode.errorSeverity; |
371 } | 372 } |
372 | 373 |
373 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { | 374 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { |
374 // we are going to ask parent file, so get absolute path | 375 // we are going to ask parent file, so get absolute path |
375 sourceFile = sourceFile.getAbsoluteFile(); | 376 sourceFile = sourceFile.getAbsoluteFile(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 445 } |
445 } | 446 } |
446 | 447 |
447 @override | 448 @override |
448 void logInformation2(String message, Object exception) { | 449 void logInformation2(String message, Object exception) { |
449 if (log) { | 450 if (log) { |
450 stdout.writeln(message); | 451 stdout.writeln(message); |
451 } | 452 } |
452 } | 453 } |
453 } | 454 } |
OLD | NEW |