Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 69851f3

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
Remove the unused type hierarchy from the completion_metrics.dart
Change-Id: I71d4f2518f107d296b359f34c4a00c0e0a472d18 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138568 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jaime Wren <[email protected]>
1 parent a2bf8dd commit 69851f3

File tree

1 file changed

+86
-107
lines changed

1 file changed

+86
-107
lines changed

pkg/analysis_server/tool/completion_metrics/completion_metrics.dart

Lines changed: 86 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,51 @@ Future<void> main(List<String> args) async {
3232
}
3333
var corpus = args[0] == '--corpus';
3434
var rootPath = corpus ? args[1] : args[0];
35-
await CompletionCoverageMetrics(rootPath).compute(corpus: corpus);
36-
io.exit(0);
35+
var code = await CompletionCoverageMetrics(rootPath).compute(corpus: corpus);
36+
io.exit(code);
3737
}
3838

3939
/// This is the main metrics computer class for code completions. After the
4040
/// object is constructed, [computeCompletionMetrics] is executed to do analysis
4141
/// and print a summary of the metrics gathered from the completion tests.
42-
abstract class AbstractCompletionMetricsComputer {
43-
// TODO(brianwilkerson) Consider merging this class into the single concrete
44-
// subclass.
42+
class CompletionCoverageMetrics {
4543
final String _rootPath;
4644

4745
String _currentFilePath;
4846

4947
ResolvedUnitResult _resolvedUnitResult;
5048

51-
AbstractCompletionMetricsComputer(this._rootPath);
49+
/// The int to be returned from the [compute] call.
50+
int resultCode;
51+
52+
int includedCount = 0;
53+
int notIncludedCount = 0;
54+
55+
var completionMissedTokenCounter = Counter('missing completion counter');
56+
var completionKindCounter = Counter('completion kind counter');
57+
var completionElementKindCounter = Counter('completion element kind counter');
58+
var mRRComputer = MeanReciprocalRankComputer();
59+
60+
CompletionCoverageMetrics(this._rootPath);
5261

5362
/// The path to the current file.
5463
String get currentFilePath => _currentFilePath;
5564

5665
/// If the concrete class has this getter return true, then when
5766
/// [forEachExpectedCompletion] is called, the [List] of
5867
/// [CompletionSuggestion]s will be passed.
59-
bool get doComputeCompletionsFromAnalysisServer;
60-
61-
/// The current [ResolvedUnitResult].
62-
ResolvedUnitResult get resolvedUnitResult => _resolvedUnitResult;
68+
bool get doComputeCompletionsFromAnalysisServer => true;
6369

6470
/// The analysis root path that this CompletionMetrics class will be computed.
6571
String get rootPath => _rootPath;
6672

67-
void compute({bool corpus = false}) async {
73+
Future<int> compute({bool corpus = false}) async {
74+
resultCode = 0;
6875
print('Analyzing root: \"$_rootPath\"');
6976

7077
if (!io.Directory(_rootPath).existsSync()) {
7178
print('\tError: No such directory exists on this machine.\n');
72-
return;
79+
return 1;
7380
}
7481

7582
var roots = _computeRootPaths(_rootPath, corpus);
@@ -85,10 +92,8 @@ abstract class AbstractCompletionMetricsComputer {
8592
var declarationsTracker = DeclarationsTracker(
8693
MemoryByteStore(), PhysicalResourceProvider.INSTANCE);
8794
declarationsTracker.addContext(context);
88-
if (doComputeCompletionsFromAnalysisServer) {
89-
while (declarationsTracker.hasWork) {
90-
declarationsTracker.doWork();
91-
}
95+
while (declarationsTracker.hasWork) {
96+
declarationsTracker.doWork();
9297
}
9398

9499
// Loop through each file, resolve the file and call
@@ -100,51 +105,102 @@ abstract class AbstractCompletionMetricsComputer {
100105
_resolvedUnitResult =
101106
await context.currentSession.getResolvedUnit(filePath);
102107

103-
var error = getFirstErrorOrNull(resolvedUnitResult);
104-
if (error != null) {
108+
var analysisError = getFirstErrorOrNull(_resolvedUnitResult);
109+
if (analysisError != null) {
105110
print('File $filePath skipped due to errors such as:');
106-
print(' ${error.toString()}');
111+
print(' ${analysisError.toString()}');
107112
print('');
113+
resultCode = 1;
108114
continue;
109115
}
110116

111117
// Use the ExpectedCompletionsVisitor to compute the set of expected
112118
// completions for this CompilationUnit.
113119
final visitor = ExpectedCompletionsVisitor();
114-
resolvedUnitResult.unit.accept(visitor);
120+
_resolvedUnitResult.unit.accept(visitor);
115121

116122
for (var expectedCompletion in visitor.expectedCompletions) {
117-
// Call forEachExpectedCompletion, passing in the computed
118-
// suggestions only if doComputeCompletionsFromAnalysisServer is
119-
// true:
120123
forEachExpectedCompletion(
121124
expectedCompletion,
122125
doComputeCompletionsFromAnalysisServer
123126
? await _computeCompletionSuggestions(
124-
resolvedUnitResult,
127+
_resolvedUnitResult,
125128
expectedCompletion.offset,
126129
declarationsTracker)
127130
: null);
128131
}
129132
} catch (e) {
130133
print('Exception caught analyzing: $filePath');
131134
print(e.toString());
135+
resultCode = 1;
132136
}
133137
}
134138
}
135139
}
136140
}
137141
printAndClearComputers();
142+
return resultCode;
138143
}
139144

140-
/// Overridden by each subclass, this method gathers some set of data from
141-
/// each [ExpectedCompletion], and each [CompletionSuggestion] list (if
142-
/// [doComputeCompletionsFromAnalysisServer] is set to true.)
143145
void forEachExpectedCompletion(ExpectedCompletion expectedCompletion,
144-
List<CompletionSuggestion> suggestions);
146+
List<CompletionSuggestion> suggestions) {
147+
assert(suggestions != null);
145148

146-
/// This method is called to print a summary of the data collected.
147-
void printAndClearComputers();
149+
var place = placementInSuggestionList(suggestions, expectedCompletion);
150+
151+
mRRComputer.addRank(place.rank);
152+
153+
if (place.denominator != 0) {
154+
includedCount++;
155+
} else {
156+
notIncludedCount++;
157+
158+
completionMissedTokenCounter.count(expectedCompletion.completion);
159+
completionKindCounter.count(expectedCompletion.kind.toString());
160+
completionElementKindCounter
161+
.count(expectedCompletion.elementKind.toString());
162+
163+
// The format "/file/path/foo.dart:3:4" makes for easier input
164+
// with the Files dialog in IntelliJ
165+
print(
166+
'$currentFilePath:${expectedCompletion.lineNumber}:${expectedCompletion.columnNumber}');
167+
print(
168+
'\tdid not include the expected completion: \"${expectedCompletion.completion}\", completion kind: ${expectedCompletion.kind.toString()}, element kind: ${expectedCompletion.elementKind.toString()}');
169+
print('');
170+
}
171+
}
172+
173+
void printAndClearComputers() {
174+
final totalCompletionCount = includedCount + notIncludedCount;
175+
final percentIncluded = includedCount / totalCompletionCount;
176+
final percentNotIncluded = 1 - percentIncluded;
177+
178+
completionMissedTokenCounter.printCounterValues();
179+
print('');
180+
181+
completionKindCounter.printCounterValues();
182+
print('');
183+
184+
completionElementKindCounter.printCounterValues();
185+
print('');
186+
187+
mRRComputer.printMean();
188+
print('');
189+
190+
print('Summary for $_rootPath:');
191+
print('Total number of completion tests = $totalCompletionCount');
192+
print(
193+
'Number of successful completions = $includedCount (${printPercentage(percentIncluded)})');
194+
print(
195+
'Number of unsuccessful completions = $notIncludedCount (${printPercentage(percentNotIncluded)})');
196+
197+
includedCount = 0;
198+
notIncludedCount = 0;
199+
completionMissedTokenCounter.clear();
200+
completionKindCounter.clear();
201+
completionElementKindCounter.clear();
202+
mRRComputer.clear();
203+
}
148204

149205
Future<List<CompletionSuggestion>> _computeCompletionSuggestions(
150206
ResolvedUnitResult resolvedUnitResult, int offset,
@@ -225,80 +281,3 @@ abstract class AbstractCompletionMetricsComputer {
225281
return Place.none();
226282
}
227283
}
228-
229-
class CompletionCoverageMetrics extends AbstractCompletionMetricsComputer {
230-
int includedCount = 0;
231-
int notIncludedCount = 0;
232-
var completionMissedTokenCounter = Counter('missing completion counter');
233-
var completionKindCounter = Counter('completion kind counter');
234-
var completionElementKindCounter = Counter('completion element kind counter');
235-
var mRRComputer = MeanReciprocalRankComputer();
236-
237-
CompletionCoverageMetrics(String rootPath) : super(rootPath);
238-
239-
@override
240-
bool get doComputeCompletionsFromAnalysisServer => true;
241-
242-
@override
243-
void forEachExpectedCompletion(ExpectedCompletion expectedCompletion,
244-
List<CompletionSuggestion> suggestions) {
245-
assert(suggestions != null);
246-
247-
var place = AbstractCompletionMetricsComputer.placementInSuggestionList(
248-
suggestions, expectedCompletion);
249-
250-
mRRComputer.addRank(place.rank);
251-
252-
if (place.denominator != 0) {
253-
includedCount++;
254-
} else {
255-
notIncludedCount++;
256-
257-
completionMissedTokenCounter.count(expectedCompletion.completion);
258-
completionKindCounter.count(expectedCompletion.kind.toString());
259-
completionElementKindCounter
260-
.count(expectedCompletion.elementKind.toString());
261-
262-
// The format "/file/path/foo.dart:3:4" makes for easier input
263-
// with the Files dialog in IntelliJ
264-
print(
265-
'$currentFilePath:${expectedCompletion.lineNumber}:${expectedCompletion.columnNumber}');
266-
print(
267-
'\tdid not include the expected completion: \"${expectedCompletion.completion}\", completion kind: ${expectedCompletion.kind.toString()}, element kind: ${expectedCompletion.elementKind.toString()}');
268-
print('');
269-
}
270-
}
271-
272-
@override
273-
void printAndClearComputers() {
274-
final totalCompletionCount = includedCount + notIncludedCount;
275-
final percentIncluded = includedCount / totalCompletionCount;
276-
final percentNotIncluded = 1 - percentIncluded;
277-
278-
completionMissedTokenCounter.printCounterValues();
279-
print('');
280-
281-
completionKindCounter.printCounterValues();
282-
print('');
283-
284-
completionElementKindCounter.printCounterValues();
285-
print('');
286-
287-
mRRComputer.printMean();
288-
print('');
289-
290-
print('Summary for $_rootPath:');
291-
print('Total number of completion tests = $totalCompletionCount');
292-
print(
293-
'Number of successful completions = $includedCount (${printPercentage(percentIncluded)})');
294-
print(
295-
'Number of unsuccessful completions = $notIncludedCount (${printPercentage(percentNotIncluded)})');
296-
297-
includedCount = 0;
298-
notIncludedCount = 0;
299-
completionMissedTokenCounter.clear();
300-
completionKindCounter.clear();
301-
completionElementKindCounter.clear();
302-
mRRComputer.clear();
303-
}
304-
}

0 commit comments

Comments
 (0)