Skip to content

Commit a95be7f

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Make MatchKind an enum
I tried to make it lowerCamelCase, but there are some generalized tests in server_protocol_test.dart that make that... difficult. I decided to punt it for later. Change-Id: I5aff5a1b27cb6a281146fb0ed10578f1bd85be11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459241 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 727ca50 commit a95be7f

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

pkg/analysis_server/lib/src/services/search/search_engine.dart

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// The `MatchKind` enum names currently match the names of `SearchResultKind`
6+
// values, including case. This is asserted in `test/protocol_server_test.dart`,
7+
// but it's not clear whether it's actually important.
8+
// ignore_for_file: constant_identifier_names
9+
510
import 'package:analyzer/dart/element/element.dart';
611
import 'package:analyzer/source/source.dart';
712
import 'package:analyzer/source/source_range.dart';
@@ -12,61 +17,47 @@ import 'package:analyzer/src/util/performance/operation_performance.dart';
1217

1318
/// Instances of the enum [MatchKind] represent the kind of reference that was
1419
/// found when a match represents a reference to an element.
15-
class MatchKind {
20+
enum MatchKind {
1621
/// A declaration of an element.
17-
static const MatchKind DECLARATION = MatchKind('DECLARATION');
22+
DECLARATION(),
1823

1924
/// A reference to an element in which it is being read.
20-
static const MatchKind READ = MatchKind('READ');
25+
READ(),
2126

2227
/// A reference to an element in which it is being both read and written.
23-
static const MatchKind READ_WRITE = MatchKind('READ_WRITE');
28+
READ_WRITE(),
2429

2530
/// A reference to an element in which it is being written.
26-
static const MatchKind WRITE = MatchKind('WRITE');
31+
WRITE(),
2732

2833
/// A reference to an element in which it is being invoked.
29-
static const MatchKind INVOCATION = MatchKind('INVOCATION');
34+
INVOCATION(),
3035

3136
/// An invocation of an enum constructor from an enum constant without
3237
/// arguments.
33-
static const MatchKind INVOCATION_BY_ENUM_CONSTANT_WITHOUT_ARGUMENTS =
34-
MatchKind('INVOCATION_BY_ENUM_CONSTANT_WITHOUT_ARGUMENTS');
38+
INVOCATION_BY_ENUM_CONSTANT_WITHOUT_ARGUMENTS(),
3539

3640
/// A reference to an element in which it is referenced.
37-
static const MatchKind REFERENCE = MatchKind.reference('REFERENCE');
41+
REFERENCE(isReference: true),
3842

3943
/// A tear-off reference to a constructor.
40-
static const MatchKind REFERENCE_BY_CONSTRUCTOR_TEAR_OFF =
41-
MatchKind.reference('REFERENCE_BY_CONSTRUCTOR_TEAR_OFF');
44+
REFERENCE_BY_CONSTRUCTOR_TEAR_OFF(isReference: true),
4245

4346
/// A reference to an element in an extends clause.
44-
static const MatchKind REFERENCE_IN_EXTENDS_CLAUSE = MatchKind.reference(
45-
'REFERENCE_IN_EXTENDS_CLAUSE',
46-
);
47+
REFERENCE_IN_EXTENDS_CLAUSE(isReference: true),
4748

4849
/// A reference to an element in an implements clause.
49-
static const MatchKind REFERENCE_IN_IMPLEMENTS_CLAUSE = MatchKind.reference(
50-
'REFERENCE_IN_IMPLEMENTS_CLAUSE',
51-
);
50+
REFERENCE_IN_IMPLEMENTS_CLAUSE(isReference: true),
5251

5352
/// A reference to an element in a with clause.
54-
static const MatchKind REFERENCE_IN_WITH_CLAUSE = MatchKind.reference(
55-
'REFERENCE_IN_WITH_CLAUSE',
56-
);
53+
REFERENCE_IN_WITH_CLAUSE(isReference: true),
5754

5855
/// A reference to an element in an on clause.
59-
static const MatchKind REFERENCE_IN_ON_CLAUSE = MatchKind.reference(
60-
'REFERENCE_IN_ON_CLAUSE',
61-
);
62-
63-
final String name;
56+
REFERENCE_IN_ON_CLAUSE(isReference: true);
6457

6558
final bool isReference;
6659

67-
const MatchKind(this.name) : isReference = false;
68-
69-
const MatchKind.reference(this.name) : isReference = true;
60+
const MatchKind({this.isReference = false});
7061

7162
@override
7263
String toString() => name;

0 commit comments

Comments
 (0)