Skip to content

Commit f87e62e

Browse files
committed
Convert subclasses of Enum
[email protected] Review URL: https://codereview.chromium.org/2365553004 .
1 parent 5e6dc0e commit f87e62e

File tree

11 files changed

+294
-310
lines changed

11 files changed

+294
-310
lines changed

pkg/analyzer/lib/dart/element/element.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import 'package:analyzer/dart/ast/ast.dart';
4040
import 'package:analyzer/dart/constant/value.dart';
4141
import 'package:analyzer/dart/element/type.dart';
4242
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
43-
import 'package:analyzer/src/generated/java_core.dart';
4443
import 'package:analyzer/src/generated/java_engine.dart';
4544
import 'package:analyzer/src/generated/resolver.dart';
4645
import 'package:analyzer/src/generated/source.dart';
@@ -864,12 +863,11 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
864863
}
865864

866865
/**
867-
* The enumeration `ElementKind` defines the various kinds of elements in the
868-
* element model.
866+
* The kind of elements in the element model.
869867
*
870868
* Clients may not extend, implement or mix-in this class.
871869
*/
872-
class ElementKind extends Enum<ElementKind> {
870+
class ElementKind implements Comparable<ElementKind> {
873871
static const ElementKind CLASS = const ElementKind('CLASS', 0, "class");
874872

875873
static const ElementKind COMPILATION_UNIT =
@@ -953,6 +951,16 @@ class ElementKind extends Enum<ElementKind> {
953951
UNIVERSE
954952
];
955953

954+
/**
955+
* The name of this element kind.
956+
*/
957+
final String name;
958+
959+
/**
960+
* The ordinal value of the element kind.
961+
*/
962+
final int ordinal;
963+
956964
/**
957965
* The name displayed in the UI for this kind of element.
958966
*/
@@ -961,8 +969,16 @@ class ElementKind extends Enum<ElementKind> {
961969
/**
962970
* Initialize a newly created element kind to have the given [displayName].
963971
*/
964-
const ElementKind(String name, int ordinal, this.displayName)
965-
: super(name, ordinal);
972+
const ElementKind(this.name, this.ordinal, this.displayName);
973+
974+
@override
975+
int get hashCode => ordinal;
976+
977+
@override
978+
int compareTo(ElementKind other) => ordinal - other.ordinal;
979+
980+
@override
981+
String toString() => name;
966982

967983
/**
968984
* Return the kind of the given [element], or [ERROR] if the element is

pkg/analyzer/lib/error/error.dart

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ abstract class ErrorCode {
892892
/**
893893
* The properties that can be associated with an [AnalysisError].
894894
*/
895-
class ErrorProperty<V> extends Enum<ErrorProperty> {
895+
class ErrorProperty<V> implements Comparable<ErrorProperty> {
896896
/**
897897
* A property whose value is a list of [FieldElement]s that are final, but
898898
* not initialized by a constructor.
@@ -921,13 +921,32 @@ class ErrorProperty<V> extends Enum<ErrorProperty> {
921921
UNIMPLEMENTED_METHODS
922922
];
923923

924-
const ErrorProperty(String name, int ordinal) : super(name, ordinal);
924+
/**
925+
* The name of this property.
926+
*/
927+
final String name;
928+
929+
/**
930+
* The ordinal value of the property.
931+
*/
932+
final int ordinal;
933+
934+
const ErrorProperty(this.name, this.ordinal);
935+
936+
@override
937+
int get hashCode => ordinal;
938+
939+
@override
940+
int compareTo(ErrorProperty other) => ordinal - other.ordinal;
941+
942+
@override
943+
String toString() => name;
925944
}
926945

927946
/**
928947
* The severity of an [ErrorCode].
929948
*/
930-
class ErrorSeverity extends Enum<ErrorSeverity> {
949+
class ErrorSeverity implements Comparable<ErrorSeverity> {
931950
/**
932951
* The severity representing a non-error. This is never used for any error
933952
* code, but is useful for clients.
@@ -954,6 +973,16 @@ class ErrorSeverity extends Enum<ErrorSeverity> {
954973

955974
static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
956975

976+
/**
977+
* The name of this error code.
978+
*/
979+
final String name;
980+
981+
/**
982+
* The ordinal value of the error code.
983+
*/
984+
final int ordinal;
985+
957986
/**
958987
* The name of the severity used when producing machine output.
959988
*/
@@ -966,26 +995,30 @@ class ErrorSeverity extends Enum<ErrorSeverity> {
966995

967996
/**
968997
* Initialize a newly created severity with the given names.
969-
*
970-
* Parameters:
971-
* 0: the name of the severity used when producing machine output
972-
* 1: the name of the severity used when producing readable output
973998
*/
974999
const ErrorSeverity(
975-
String name, int ordinal, this.machineCode, this.displayName)
976-
: super(name, ordinal);
1000+
this.name, this.ordinal, this.machineCode, this.displayName);
1001+
1002+
@override
1003+
int get hashCode => ordinal;
1004+
1005+
@override
1006+
int compareTo(ErrorSeverity other) => ordinal - other.ordinal;
9771007

9781008
/**
9791009
* Return the severity constant that represents the greatest severity.
9801010
*/
9811011
ErrorSeverity max(ErrorSeverity severity) =>
9821012
this.ordinal >= severity.ordinal ? this : severity;
1013+
1014+
@override
1015+
String toString() => name;
9831016
}
9841017

9851018
/**
9861019
* The type of an [ErrorCode].
9871020
*/
988-
class ErrorType extends Enum<ErrorType> {
1021+
class ErrorType implements Comparable<ErrorType> {
9891022
/**
9901023
* Task (todo) comments in user code.
9911024
*/
@@ -1051,6 +1084,16 @@ class ErrorType extends Enum<ErrorType> {
10511084
LINT
10521085
];
10531086

1087+
/**
1088+
* The name of this error type.
1089+
*/
1090+
final String name;
1091+
1092+
/**
1093+
* The ordinal value of the error type.
1094+
*/
1095+
final int ordinal;
1096+
10541097
/**
10551098
* The severity of this type of error.
10561099
*/
@@ -1060,8 +1103,16 @@ class ErrorType extends Enum<ErrorType> {
10601103
* Initialize a newly created error type to have the given [name] and
10611104
* [severity].
10621105
*/
1063-
const ErrorType(String name, int ordinal, this.severity)
1064-
: super(name, ordinal);
1106+
const ErrorType(this.name, this.ordinal, this.severity);
10651107

10661108
String get displayName => name.toLowerCase().replaceAll('_', ' ');
1109+
1110+
@override
1111+
int get hashCode => ordinal;
1112+
1113+
@override
1114+
int compareTo(ErrorType other) => ordinal - other.ordinal;
1115+
1116+
@override
1117+
String toString() => name;
10671118
}

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import 'package:analyzer/src/error/codes.dart' show CompileTimeErrorCode;
2121
import 'package:analyzer/src/generated/constant.dart' show EvaluationResultImpl;
2222
import 'package:analyzer/src/generated/engine.dart'
2323
show AnalysisContext, AnalysisEngine;
24-
import 'package:analyzer/src/generated/java_core.dart';
2524
import 'package:analyzer/src/generated/java_engine.dart';
2625
import 'package:analyzer/src/generated/resolver.dart';
2726
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
@@ -3074,7 +3073,7 @@ abstract class ElementImpl implements Element {
30743073
* Return `true` if this element has the given [modifier] associated with it.
30753074
*/
30763075
bool hasModifier(Modifier modifier) =>
3077-
BooleanArray.getEnum(_modifiers, modifier);
3076+
BooleanArray.get(_modifiers, modifier.ordinal);
30783077

30793078
@override
30803079
bool isAccessibleIn(LibraryElement library) {
@@ -3109,7 +3108,7 @@ abstract class ElementImpl implements Element {
31093108
* correspond to the given [value].
31103109
*/
31113110
void setModifier(Modifier modifier, bool value) {
3112-
_modifiers = BooleanArray.setEnum(_modifiers, modifier, value);
3111+
_modifiers = BooleanArray.set(_modifiers, modifier.ordinal, value);
31133112
}
31143113

31153114
@override
@@ -6179,12 +6178,12 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
61796178
}
61806179

61816180
/**
6182-
* The enumeration `Modifier` defines constants for all of the modifiers defined
6183-
* by the Dart language and for a few additional flags that are useful.
6181+
* The constants for all of the modifiers defined by the Dart language and for a
6182+
* few additional flags that are useful.
61846183
*
61856184
* Clients may not extend, implement or mix-in this class.
61866185
*/
6187-
class Modifier extends Enum<Modifier> {
6186+
class Modifier implements Comparable<Modifier> {
61886187
/**
61896188
* Indicates that the modifier 'abstract' was applied to the element.
61906189
*/
@@ -6301,7 +6300,26 @@ class Modifier extends Enum<Modifier> {
63016300
SYNTHETIC
63026301
];
63036302

6304-
const Modifier(String name, int ordinal) : super(name, ordinal);
6303+
/**
6304+
* The name of this modifier.
6305+
*/
6306+
final String name;
6307+
6308+
/**
6309+
* The ordinal value of the modifier.
6310+
*/
6311+
final int ordinal;
6312+
6313+
const Modifier(this.name, this.ordinal);
6314+
6315+
@override
6316+
int get hashCode => ordinal;
6317+
6318+
@override
6319+
int compareTo(Modifier other) => ordinal - other.ordinal;
6320+
6321+
@override
6322+
String toString() => name;
63056323
}
63066324

63076325
/**

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -950,19 +950,21 @@ class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
950950
/**
951951
* The levels at which a source can be analyzed.
952952
*/
953-
class AnalysisLevel extends Enum<AnalysisLevel> {
953+
class AnalysisLevel implements Comparable<AnalysisLevel> {
954954
/**
955955
* Indicates a source should be fully analyzed.
956956
*/
957957
static const AnalysisLevel ALL = const AnalysisLevel('ALL', 0);
958958

959959
/**
960-
* Indicates a source should be resolved and that errors, warnings and hints are needed.
960+
* Indicates a source should be resolved and that errors, warnings and hints
961+
* are needed.
961962
*/
962963
static const AnalysisLevel ERRORS = const AnalysisLevel('ERRORS', 1);
963964

964965
/**
965-
* Indicates a source should be resolved, but that errors, warnings and hints are not needed.
966+
* Indicates a source should be resolved, but that errors, warnings and hints
967+
* are not needed.
966968
*/
967969
static const AnalysisLevel RESOLVED = const AnalysisLevel('RESOLVED', 2);
968970

@@ -973,7 +975,26 @@ class AnalysisLevel extends Enum<AnalysisLevel> {
973975

974976
static const List<AnalysisLevel> values = const [ALL, ERRORS, RESOLVED, NONE];
975977

976-
const AnalysisLevel(String name, int ordinal) : super(name, ordinal);
978+
/**
979+
* The name of this analysis level.
980+
*/
981+
final String name;
982+
983+
/**
984+
* The ordinal value of the analysis level.
985+
*/
986+
final int ordinal;
987+
988+
const AnalysisLevel(this.name, this.ordinal);
989+
990+
@override
991+
int get hashCode => ordinal;
992+
993+
@override
994+
int compareTo(AnalysisLevel other) => ordinal - other.ordinal;
995+
996+
@override
997+
String toString() => name;
977998
}
978999

9791000
/**
@@ -1229,13 +1250,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
12291250
@override
12301251
bool enableAssertMessage = false;
12311252

1232-
@deprecated
1233-
@override
1234-
bool get enableAsync => true;
1235-
1236-
@deprecated
1237-
void set enableAsync(bool enable) {}
1238-
12391253
@override
12401254
bool enableGenericMethods = false;
12411255

@@ -1391,6 +1405,13 @@ class AnalysisOptionsImpl implements AnalysisOptions {
13911405
_analyzeFunctionBodiesPredicate = value;
13921406
}
13931407

1408+
@deprecated
1409+
@override
1410+
bool get enableAsync => true;
1411+
1412+
@deprecated
1413+
void set enableAsync(bool enable) {}
1414+
13941415
/**
13951416
* A flag indicating whether interface libraries are to be supported (DEP 40).
13961417
*/
@@ -1578,7 +1599,7 @@ abstract class CacheConsistencyValidator {
15781599
/**
15791600
* The possible states of cached data.
15801601
*/
1581-
class CacheState extends Enum<CacheState> {
1602+
class CacheState implements Comparable<CacheState> {
15821603
/**
15831604
* The data is not in the cache and the last time an attempt was made to
15841605
* compute the data an exception occurred, making it pointless to attempt to
@@ -1639,7 +1660,26 @@ class CacheState extends Enum<CacheState> {
16391660
VALID
16401661
];
16411662

1642-
const CacheState(String name, int ordinal) : super(name, ordinal);
1663+
/**
1664+
* The name of this cache state.
1665+
*/
1666+
final String name;
1667+
1668+
/**
1669+
* The ordinal value of the cache state.
1670+
*/
1671+
final int ordinal;
1672+
1673+
const CacheState(this.name, this.ordinal);
1674+
1675+
@override
1676+
int get hashCode => ordinal;
1677+
1678+
@override
1679+
int compareTo(CacheState other) => ordinal - other.ordinal;
1680+
1681+
@override
1682+
String toString() => name;
16431683
}
16441684

16451685
/**

pkg/analyzer/lib/src/generated/java_core.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class Character {
125125
}
126126
}
127127

128+
@deprecated
128129
abstract class Enum<E extends Enum> implements Comparable<E> {
129130
/// The name of this enum constant, as declared in the enum declaration.
130131
final String name;

0 commit comments

Comments
 (0)