Skip to content

Commit 4ad5fab

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
Refactor _placementInSuggestionList to not use the dart:math Point class to represent Place, this has been replaced by a new class.
Change-Id: I6750667e878e16c816caa80760fd8763bba97ccb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132780 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Jaime Wren <jwren@google.com>
1 parent 7295841 commit 4ad5fab

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

pkg/analysis_server/tool/completion_metrics/completion_metrics.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66
import 'dart:io' as io;
7-
import 'dart:math';
87

98
import 'package:analysis_server/src/domains/completion/available_suggestions.dart';
109
import 'package:analysis_server/src/protocol_server.dart';
@@ -83,7 +82,7 @@ Future _computeCompletionMetrics(
8382
var fraction =
8483
_placementInSuggestionList(suggestions, expectedCompletion);
8584

86-
if (fraction.y != 0) {
85+
if (fraction.denominator != 0) {
8786
includedCount++;
8887
} else {
8988
notIncludedCount++;
@@ -130,16 +129,16 @@ Future _computeCompletionMetrics(
130129
completionElementKindCounter.clear();
131130
}
132131

133-
Point<int> _placementInSuggestionList(List<CompletionSuggestion> suggestions,
132+
Place _placementInSuggestionList(List<CompletionSuggestion> suggestions,
134133
ExpectedCompletion expectedCompletion) {
135-
var i = 1;
134+
var placeCounter = 1;
136135
for (var completionSuggestion in suggestions) {
137136
if (expectedCompletion.matches(completionSuggestion)) {
138-
return Point(i, suggestions.length);
137+
return Place(placeCounter, suggestions.length);
139138
}
140-
i++;
139+
placeCounter++;
141140
}
142-
return Point(0, 0);
141+
return Place.none();
143142
}
144143

145144
Future<List<CompletionSuggestion>> computeCompletionSuggestions(

pkg/analysis_server/tool/completion_metrics/metrics_util.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/src/status/pages.dart';
6+
import 'package:analyzer/src/generated/utilities_general.dart';
67

78
/// A simple counter class. A [String] name is passed to name the counter. Each
89
/// time something is counted, a non-null, non-empty [String] key is passed to
@@ -54,3 +55,34 @@ class Counter {
5455
print('');
5556
}
5657
}
58+
59+
/// An immutable class to represent the placement in some list, for example '2nd
60+
/// place out of 5'.
61+
class Place {
62+
/// A 1-indexed place in a list
63+
final int _numerator;
64+
65+
/// The total number of possible places.
66+
final int _denominator;
67+
68+
Place(this._numerator, this._denominator) {
69+
assert(_numerator > 0 && _denominator > 0);
70+
}
71+
72+
Place.none()
73+
: _numerator = 0,
74+
_denominator = 0;
75+
76+
int get denominator => _denominator;
77+
78+
@override
79+
int get hashCode => JenkinsSmiHash.hash2(_numerator, _denominator);
80+
81+
int get numerator => _numerator;
82+
83+
@override
84+
bool operator ==(dynamic other) =>
85+
other is Place &&
86+
_numerator == other._numerator &&
87+
_denominator == other._denominator;
88+
}

0 commit comments

Comments
 (0)