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 library analyzer_cli.src.analyzer_impl; | 5 library analyzer_cli.src.analyzer_impl; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/source/error_processor.dart'; | 11 import 'package:analyzer/source/error_processor.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
14 import 'package:analyzer/src/generated/java_engine.dart'; | 14 import 'package:analyzer/src/generated/java_engine.dart'; |
15 import 'package:analyzer/src/generated/java_io.dart'; | 15 import 'package:analyzer/src/generated/java_io.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:analyzer/src/generated/source_io.dart'; | 17 import 'package:analyzer/src/generated/source_io.dart'; |
18 import 'package:analyzer/src/generated/utilities_general.dart'; | 18 import 'package:analyzer/src/generated/utilities_general.dart'; |
19 import 'package:analyzer_cli/src/driver.dart'; | 19 import 'package:analyzer_cli/src/driver.dart'; |
20 import 'package:analyzer_cli/src/error_formatter.dart'; | 20 import 'package:analyzer_cli/src/error_formatter.dart'; |
| 21 import 'package:analyzer_cli/src/incremental_analyzer.dart'; |
21 import 'package:analyzer_cli/src/options.dart'; | 22 import 'package:analyzer_cli/src/options.dart'; |
22 import 'package:path/path.dart' as pathos; | 23 import 'package:path/path.dart' as pathos; |
23 | 24 |
24 /// The maximum number of sources for which AST structures should be kept in the
cache. | 25 /// The maximum number of sources for which AST structures should be kept in the
cache. |
25 const int _maxCacheSize = 512; | 26 const int _maxCacheSize = 512; |
26 | 27 |
27 int currentTimeMillis() => new DateTime.now().millisecondsSinceEpoch; | 28 int currentTimeMillis() => new DateTime.now().millisecondsSinceEpoch; |
28 | 29 |
29 /// Analyzes single library [File]. | 30 /// Analyzes single library [File]. |
30 class AnalyzerImpl { | 31 class AnalyzerImpl { |
31 static final PerformanceTag _prepareErrorsTag = | 32 static final PerformanceTag _prepareErrorsTag = |
32 new PerformanceTag("AnalyzerImpl.prepareErrors"); | 33 new PerformanceTag("AnalyzerImpl.prepareErrors"); |
33 static final PerformanceTag _resolveLibraryTag = | 34 static final PerformanceTag _resolveLibraryTag = |
34 new PerformanceTag("AnalyzerImpl._resolveLibrary"); | 35 new PerformanceTag("AnalyzerImpl._resolveLibrary"); |
35 | 36 |
36 final CommandLineOptions options; | 37 final CommandLineOptions options; |
37 final int startTime; | 38 final int startTime; |
38 | 39 |
39 final AnalysisContext context; | 40 final AnalysisContext context; |
40 | 41 |
| 42 final IncrementalAnalysisSession incrementalSession; |
| 43 |
41 /// Accumulated analysis statistics. | 44 /// Accumulated analysis statistics. |
42 final AnalysisStats stats; | 45 final AnalysisStats stats; |
43 | 46 |
44 final Source librarySource; | 47 final Source librarySource; |
45 | 48 |
46 /// All [Source]s references by the analyzed library. | 49 /// All [Source]s references by the analyzed library. |
47 final Set<Source> sources = new Set<Source>(); | 50 final Set<Source> sources = new Set<Source>(); |
48 | 51 |
49 /// All [AnalysisErrorInfo]s in the analyzed library. | 52 /// All [AnalysisErrorInfo]s in the analyzed library. |
50 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); | 53 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); |
51 | 54 |
52 /// [HashMap] between sources and analysis error infos. | 55 /// [HashMap] between sources and analysis error infos. |
53 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = | 56 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = |
54 new HashMap<Source, AnalysisErrorInfo>(); | 57 new HashMap<Source, AnalysisErrorInfo>(); |
55 | 58 |
56 /// If the file specified on the command line is part of a package, the name | 59 /// If the file specified on the command line is part of a package, the name |
57 /// of that package. Otherwise `null`. This allows us to analyze the file | 60 /// of that package. Otherwise `null`. This allows us to analyze the file |
58 /// specified on the command line as though it is reached via a "package:" | 61 /// specified on the command line as though it is reached via a "package:" |
59 /// URI, but avoid suppressing its output in the event that the user has not | 62 /// URI, but avoid suppressing its output in the event that the user has not |
60 /// specified the "--package-warnings" option. | 63 /// specified the "--package-warnings" option. |
61 String _selfPackageName; | 64 String _selfPackageName; |
62 | 65 |
63 AnalyzerImpl(this.context, this.librarySource, this.options, this.stats, | 66 AnalyzerImpl(this.context, this.incrementalSession, this.librarySource, |
64 this.startTime); | 67 this.options, this.stats, this.startTime); |
65 | 68 |
66 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 69 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
67 ErrorSeverity get maxErrorSeverity { | 70 ErrorSeverity get maxErrorSeverity { |
68 var status = ErrorSeverity.NONE; | 71 var status = ErrorSeverity.NONE; |
69 for (AnalysisErrorInfo errorInfo in errorInfos) { | 72 for (AnalysisErrorInfo errorInfo in errorInfos) { |
70 for (AnalysisError error in errorInfo.errors) { | 73 for (AnalysisError error in errorInfo.errors) { |
71 if (_processError(error) == null) { | 74 if (_processError(error) == null) { |
72 continue; | 75 continue; |
73 } | 76 } |
74 var severity = computeSeverity(error, options); | 77 var severity = computeSeverity(error, options); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 errorInfos.add(context.getErrors(source)); | 131 errorInfos.add(context.getErrors(source)); |
129 } | 132 } |
130 }); | 133 }); |
131 } | 134 } |
132 | 135 |
133 /// Fills [sources]. | 136 /// Fills [sources]. |
134 void prepareSources(LibraryElement library) { | 137 void prepareSources(LibraryElement library) { |
135 var units = new Set<CompilationUnitElement>(); | 138 var units = new Set<CompilationUnitElement>(); |
136 var libraries = new Set<LibraryElement>(); | 139 var libraries = new Set<LibraryElement>(); |
137 addLibrarySources(library, libraries, units); | 140 addLibrarySources(library, libraries, units); |
| 141 incrementalSession?.setAnalyzedSources(sources); |
138 } | 142 } |
139 | 143 |
140 /// Setup local fields such as the analysis context for analysis. | 144 /// Setup local fields such as the analysis context for analysis. |
141 void setupForAnalysis() { | 145 void setupForAnalysis() { |
142 sources.clear(); | 146 sources.clear(); |
143 errorInfos.clear(); | 147 errorInfos.clear(); |
144 Uri libraryUri = librarySource.uri; | 148 Uri libraryUri = librarySource.uri; |
145 if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { | 149 if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { |
146 _selfPackageName = libraryUri.pathSegments[0]; | 150 _selfPackageName = libraryUri.pathSegments[0]; |
147 } | 151 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 363 } |
360 | 364 |
361 @override | 365 @override |
362 void logInformation(String message, [CaughtException exception]) { | 366 void logInformation(String message, [CaughtException exception]) { |
363 outSink.writeln(message); | 367 outSink.writeln(message); |
364 if (exception != null) { | 368 if (exception != null) { |
365 outSink.writeln(exception); | 369 outSink.writeln(exception); |
366 } | 370 } |
367 } | 371 } |
368 } | 372 } |
OLD | NEW |