mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:39:19 +00:00
Convert subclasses of Enum
R=scheglov@google.com Review URL: https://codereview.chromium.org/2365553004 .
This commit is contained in:
parent
5e6dc0e0d8
commit
f87e62ef14
|
@ -40,7 +40,6 @@ import 'package:analyzer/dart/ast/ast.dart';
|
|||
import 'package:analyzer/dart/constant/value.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
|
||||
import 'package:analyzer/src/generated/java_core.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/resolver.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
@ -864,12 +863,11 @@ abstract class ElementAnnotation implements ConstantEvaluationTarget {
|
|||
}
|
||||
|
||||
/**
|
||||
* The enumeration `ElementKind` defines the various kinds of elements in the
|
||||
* element model.
|
||||
* The kind of elements in the element model.
|
||||
*
|
||||
* Clients may not extend, implement or mix-in this class.
|
||||
*/
|
||||
class ElementKind extends Enum<ElementKind> {
|
||||
class ElementKind implements Comparable<ElementKind> {
|
||||
static const ElementKind CLASS = const ElementKind('CLASS', 0, "class");
|
||||
|
||||
static const ElementKind COMPILATION_UNIT =
|
||||
|
@ -953,6 +951,16 @@ class ElementKind extends Enum<ElementKind> {
|
|||
UNIVERSE
|
||||
];
|
||||
|
||||
/**
|
||||
* The name of this element kind.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the element kind.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* The name displayed in the UI for this kind of element.
|
||||
*/
|
||||
|
@ -961,8 +969,16 @@ class ElementKind extends Enum<ElementKind> {
|
|||
/**
|
||||
* Initialize a newly created element kind to have the given [displayName].
|
||||
*/
|
||||
const ElementKind(String name, int ordinal, this.displayName)
|
||||
: super(name, ordinal);
|
||||
const ElementKind(this.name, this.ordinal, this.displayName);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(ElementKind other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
||||
/**
|
||||
* Return the kind of the given [element], or [ERROR] if the element is
|
||||
|
|
|
@ -892,7 +892,7 @@ abstract class ErrorCode {
|
|||
/**
|
||||
* The properties that can be associated with an [AnalysisError].
|
||||
*/
|
||||
class ErrorProperty<V> extends Enum<ErrorProperty> {
|
||||
class ErrorProperty<V> implements Comparable<ErrorProperty> {
|
||||
/**
|
||||
* A property whose value is a list of [FieldElement]s that are final, but
|
||||
* not initialized by a constructor.
|
||||
|
@ -921,13 +921,32 @@ class ErrorProperty<V> extends Enum<ErrorProperty> {
|
|||
UNIMPLEMENTED_METHODS
|
||||
];
|
||||
|
||||
const ErrorProperty(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this property.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the property.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const ErrorProperty(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(ErrorProperty other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The severity of an [ErrorCode].
|
||||
*/
|
||||
class ErrorSeverity extends Enum<ErrorSeverity> {
|
||||
class ErrorSeverity implements Comparable<ErrorSeverity> {
|
||||
/**
|
||||
* The severity representing a non-error. This is never used for any error
|
||||
* code, but is useful for clients.
|
||||
|
@ -954,6 +973,16 @@ class ErrorSeverity extends Enum<ErrorSeverity> {
|
|||
|
||||
static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
|
||||
|
||||
/**
|
||||
* The name of this error code.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the error code.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* The name of the severity used when producing machine output.
|
||||
*/
|
||||
|
@ -966,26 +995,30 @@ class ErrorSeverity extends Enum<ErrorSeverity> {
|
|||
|
||||
/**
|
||||
* Initialize a newly created severity with the given names.
|
||||
*
|
||||
* Parameters:
|
||||
* 0: the name of the severity used when producing machine output
|
||||
* 1: the name of the severity used when producing readable output
|
||||
*/
|
||||
const ErrorSeverity(
|
||||
String name, int ordinal, this.machineCode, this.displayName)
|
||||
: super(name, ordinal);
|
||||
this.name, this.ordinal, this.machineCode, this.displayName);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(ErrorSeverity other) => ordinal - other.ordinal;
|
||||
|
||||
/**
|
||||
* Return the severity constant that represents the greatest severity.
|
||||
*/
|
||||
ErrorSeverity max(ErrorSeverity severity) =>
|
||||
this.ordinal >= severity.ordinal ? this : severity;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of an [ErrorCode].
|
||||
*/
|
||||
class ErrorType extends Enum<ErrorType> {
|
||||
class ErrorType implements Comparable<ErrorType> {
|
||||
/**
|
||||
* Task (todo) comments in user code.
|
||||
*/
|
||||
|
@ -1051,6 +1084,16 @@ class ErrorType extends Enum<ErrorType> {
|
|||
LINT
|
||||
];
|
||||
|
||||
/**
|
||||
* The name of this error type.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the error type.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* The severity of this type of error.
|
||||
*/
|
||||
|
@ -1060,8 +1103,16 @@ class ErrorType extends Enum<ErrorType> {
|
|||
* Initialize a newly created error type to have the given [name] and
|
||||
* [severity].
|
||||
*/
|
||||
const ErrorType(String name, int ordinal, this.severity)
|
||||
: super(name, ordinal);
|
||||
const ErrorType(this.name, this.ordinal, this.severity);
|
||||
|
||||
String get displayName => name.toLowerCase().replaceAll('_', ' ');
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(ErrorType other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import 'package:analyzer/src/error/codes.dart' show CompileTimeErrorCode;
|
|||
import 'package:analyzer/src/generated/constant.dart' show EvaluationResultImpl;
|
||||
import 'package:analyzer/src/generated/engine.dart'
|
||||
show AnalysisContext, AnalysisEngine;
|
||||
import 'package:analyzer/src/generated/java_core.dart';
|
||||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/resolver.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
|
||||
|
@ -3074,7 +3073,7 @@ abstract class ElementImpl implements Element {
|
|||
* Return `true` if this element has the given [modifier] associated with it.
|
||||
*/
|
||||
bool hasModifier(Modifier modifier) =>
|
||||
BooleanArray.getEnum(_modifiers, modifier);
|
||||
BooleanArray.get(_modifiers, modifier.ordinal);
|
||||
|
||||
@override
|
||||
bool isAccessibleIn(LibraryElement library) {
|
||||
|
@ -3109,7 +3108,7 @@ abstract class ElementImpl implements Element {
|
|||
* correspond to the given [value].
|
||||
*/
|
||||
void setModifier(Modifier modifier, bool value) {
|
||||
_modifiers = BooleanArray.setEnum(_modifiers, modifier, value);
|
||||
_modifiers = BooleanArray.set(_modifiers, modifier.ordinal, value);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -6179,12 +6178,12 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
|
|||
}
|
||||
|
||||
/**
|
||||
* The enumeration `Modifier` defines constants for all of the modifiers defined
|
||||
* by the Dart language and for a few additional flags that are useful.
|
||||
* The constants for all of the modifiers defined by the Dart language and for a
|
||||
* few additional flags that are useful.
|
||||
*
|
||||
* Clients may not extend, implement or mix-in this class.
|
||||
*/
|
||||
class Modifier extends Enum<Modifier> {
|
||||
class Modifier implements Comparable<Modifier> {
|
||||
/**
|
||||
* Indicates that the modifier 'abstract' was applied to the element.
|
||||
*/
|
||||
|
@ -6301,7 +6300,26 @@ class Modifier extends Enum<Modifier> {
|
|||
SYNTHETIC
|
||||
];
|
||||
|
||||
const Modifier(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this modifier.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the modifier.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const Modifier(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(Modifier other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -950,19 +950,21 @@ class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
|
|||
/**
|
||||
* The levels at which a source can be analyzed.
|
||||
*/
|
||||
class AnalysisLevel extends Enum<AnalysisLevel> {
|
||||
class AnalysisLevel implements Comparable<AnalysisLevel> {
|
||||
/**
|
||||
* Indicates a source should be fully analyzed.
|
||||
*/
|
||||
static const AnalysisLevel ALL = const AnalysisLevel('ALL', 0);
|
||||
|
||||
/**
|
||||
* Indicates a source should be resolved and that errors, warnings and hints are needed.
|
||||
* Indicates a source should be resolved and that errors, warnings and hints
|
||||
* are needed.
|
||||
*/
|
||||
static const AnalysisLevel ERRORS = const AnalysisLevel('ERRORS', 1);
|
||||
|
||||
/**
|
||||
* Indicates a source should be resolved, but that errors, warnings and hints are not needed.
|
||||
* Indicates a source should be resolved, but that errors, warnings and hints
|
||||
* are not needed.
|
||||
*/
|
||||
static const AnalysisLevel RESOLVED = const AnalysisLevel('RESOLVED', 2);
|
||||
|
||||
|
@ -973,7 +975,26 @@ class AnalysisLevel extends Enum<AnalysisLevel> {
|
|||
|
||||
static const List<AnalysisLevel> values = const [ALL, ERRORS, RESOLVED, NONE];
|
||||
|
||||
const AnalysisLevel(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this analysis level.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the analysis level.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const AnalysisLevel(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(AnalysisLevel other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1229,13 +1250,6 @@ class AnalysisOptionsImpl implements AnalysisOptions {
|
|||
@override
|
||||
bool enableAssertMessage = false;
|
||||
|
||||
@deprecated
|
||||
@override
|
||||
bool get enableAsync => true;
|
||||
|
||||
@deprecated
|
||||
void set enableAsync(bool enable) {}
|
||||
|
||||
@override
|
||||
bool enableGenericMethods = false;
|
||||
|
||||
|
@ -1391,6 +1405,13 @@ class AnalysisOptionsImpl implements AnalysisOptions {
|
|||
_analyzeFunctionBodiesPredicate = value;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
@override
|
||||
bool get enableAsync => true;
|
||||
|
||||
@deprecated
|
||||
void set enableAsync(bool enable) {}
|
||||
|
||||
/**
|
||||
* A flag indicating whether interface libraries are to be supported (DEP 40).
|
||||
*/
|
||||
|
@ -1578,7 +1599,7 @@ abstract class CacheConsistencyValidator {
|
|||
/**
|
||||
* The possible states of cached data.
|
||||
*/
|
||||
class CacheState extends Enum<CacheState> {
|
||||
class CacheState implements Comparable<CacheState> {
|
||||
/**
|
||||
* The data is not in the cache and the last time an attempt was made to
|
||||
* compute the data an exception occurred, making it pointless to attempt to
|
||||
|
@ -1639,7 +1660,26 @@ class CacheState extends Enum<CacheState> {
|
|||
VALID
|
||||
];
|
||||
|
||||
const CacheState(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this cache state.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the cache state.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const CacheState(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(CacheState other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -125,6 +125,7 @@ class Character {
|
|||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
abstract class Enum<E extends Enum> implements Comparable<E> {
|
||||
/// The name of this enum constant, as declared in the enum declaration.
|
||||
final String name;
|
||||
|
|
|
@ -5007,11 +5007,11 @@ class InferenceContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* This enum holds one of four states of a field initialization state through a constructor
|
||||
* signature, not initialized, initialized in the field declaration, initialized in the field
|
||||
* formal, and finally, initialized in the initializers list.
|
||||
* The four states of a field initialization state through a constructor
|
||||
* signature, not initialized, initialized in the field declaration, initialized
|
||||
* in the field formal, and finally, initialized in the initializers list.
|
||||
*/
|
||||
class INIT_STATE extends Enum<INIT_STATE> {
|
||||
class INIT_STATE implements Comparable<INIT_STATE> {
|
||||
static const INIT_STATE NOT_INIT = const INIT_STATE('NOT_INIT', 0);
|
||||
|
||||
static const INIT_STATE INIT_IN_DECLARATION =
|
||||
|
@ -5030,7 +5030,26 @@ class INIT_STATE extends Enum<INIT_STATE> {
|
|||
INIT_IN_INITIALIZERS
|
||||
];
|
||||
|
||||
const INIT_STATE(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this init state.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the init state.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const INIT_STATE(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(INIT_STATE other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5527,7 +5546,8 @@ class PubVerifier extends RecursiveAstVisitor<Object> {
|
|||
/**
|
||||
* Kind of the redirecting constructor.
|
||||
*/
|
||||
class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> {
|
||||
class RedirectingConstructorKind
|
||||
implements Comparable<RedirectingConstructorKind> {
|
||||
static const RedirectingConstructorKind CONST =
|
||||
const RedirectingConstructorKind('CONST', 0);
|
||||
|
||||
|
@ -5536,8 +5556,26 @@ class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> {
|
|||
|
||||
static const List<RedirectingConstructorKind> values = const [CONST, NORMAL];
|
||||
|
||||
const RedirectingConstructorKind(String name, int ordinal)
|
||||
: super(name, ordinal);
|
||||
/**
|
||||
* The name of this redirecting constructor kind.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the redirecting constructor kind.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const RedirectingConstructorKind(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(RedirectingConstructorKind other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7283,8 +7321,13 @@ class ResolverVisitor extends ScopedVisitor {
|
|||
originalType is FunctionType &&
|
||||
originalType.typeFormals.isNotEmpty &&
|
||||
ts is StrongTypeSystemImpl) {
|
||||
contextType = ts.inferGenericFunctionCall(typeProvider, originalType,
|
||||
DartType.EMPTY_LIST, DartType.EMPTY_LIST, originalType.returnType, returnContextType);
|
||||
contextType = ts.inferGenericFunctionCall(
|
||||
typeProvider,
|
||||
originalType,
|
||||
DartType.EMPTY_LIST,
|
||||
DartType.EMPTY_LIST,
|
||||
originalType.returnType,
|
||||
returnContextType);
|
||||
}
|
||||
|
||||
InferenceContext.setType(node.argumentList, contextType);
|
||||
|
|
|
@ -688,7 +688,7 @@ abstract class SourceFactory {
|
|||
* The enumeration `SourceKind` defines the different kinds of sources that are
|
||||
* known to the analysis engine.
|
||||
*/
|
||||
class SourceKind extends Enum<SourceKind> {
|
||||
class SourceKind implements Comparable<SourceKind> {
|
||||
/**
|
||||
* A source containing HTML. The HTML might or might not contain Dart scripts.
|
||||
*/
|
||||
|
@ -716,7 +716,26 @@ class SourceKind extends Enum<SourceKind> {
|
|||
|
||||
static const List<SourceKind> values = const [HTML, LIBRARY, PART, UNKNOWN];
|
||||
|
||||
const SourceKind(String name, int ordinal) : super(name, ordinal);
|
||||
/**
|
||||
* The name of this source kind.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the source kind.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
const SourceKind(this.name, this.ordinal);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(SourceKind other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -848,7 +867,7 @@ class SourceRange {
|
|||
* The enumeration `UriKind` defines the different kinds of URI's that are known to the
|
||||
* analysis engine. These are used to keep track of the kind of URI associated with a given source.
|
||||
*/
|
||||
class UriKind extends Enum<UriKind> {
|
||||
class UriKind implements Comparable<UriKind> {
|
||||
/**
|
||||
* A 'dart:' URI.
|
||||
*/
|
||||
|
@ -866,6 +885,16 @@ class UriKind extends Enum<UriKind> {
|
|||
|
||||
static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_URI];
|
||||
|
||||
/**
|
||||
* The name of this URI kind.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the URI kind.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* The single character encoding used to identify this kind of URI.
|
||||
*/
|
||||
|
@ -873,17 +902,21 @@ class UriKind extends Enum<UriKind> {
|
|||
|
||||
/**
|
||||
* Initialize a newly created URI kind to have the given encoding.
|
||||
*
|
||||
* @param encoding the single character encoding used to identify this kind of URI.
|
||||
*/
|
||||
const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
|
||||
const UriKind(this.name, this.ordinal, this.encoding);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(UriKind other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
||||
/**
|
||||
* Return the URI kind represented by the given encoding, or `null` if there is no kind with
|
||||
* the given encoding.
|
||||
*
|
||||
* @param encoding the single character encoding used to identify the URI kind to be returned
|
||||
* @return the URI kind represented by the given encoding
|
||||
* Return the URI kind represented by the given [encoding], or `null` if there
|
||||
* is no kind with the given encoding.
|
||||
*/
|
||||
static UriKind fromEncoding(int encoding) {
|
||||
while (true) {
|
||||
|
|
|
@ -34,17 +34,12 @@ bool listsEqual(List a, List b) {
|
|||
}
|
||||
|
||||
/**
|
||||
* The class `BooleanArray` defines methods for operating on integers as if they were arrays
|
||||
* of booleans. These arrays can be indexed by either integers or by enumeration constants.
|
||||
* Methods for operating on integers as if they were arrays of booleans. These
|
||||
* arrays can be indexed by either integers or by enumeration constants.
|
||||
*/
|
||||
class BooleanArray {
|
||||
/**
|
||||
* Return the value of the element at the given index.
|
||||
*
|
||||
* @param array the array being accessed
|
||||
* @param index the index of the element being accessed
|
||||
* @return the value of the element at the given index
|
||||
* @throws IndexOutOfBoundsException if the index is not between zero (0) and 31, inclusive
|
||||
* Return the value of the element of the given [array] at the given [index].
|
||||
*/
|
||||
static bool get(int array, int index) {
|
||||
_checkIndex(index);
|
||||
|
@ -53,22 +48,13 @@ class BooleanArray {
|
|||
|
||||
/**
|
||||
* Return the value of the element at the given index.
|
||||
*
|
||||
* @param array the array being accessed
|
||||
* @param index the index of the element being accessed
|
||||
* @return the value of the element at the given index
|
||||
* @throws IndexOutOfBoundsException if the index is not between zero (0) and 31, inclusive
|
||||
*/
|
||||
@deprecated
|
||||
static bool getEnum(int array, Enum index) => get(array, index.ordinal);
|
||||
|
||||
/**
|
||||
* Set the value of the element at the given index to the given value.
|
||||
*
|
||||
* @param array the array being modified
|
||||
* @param index the index of the element being set
|
||||
* @param value the value to be assigned to the element
|
||||
* @return the updated value of the array
|
||||
* @throws IndexOutOfBoundsException if the index is not between zero (0) and 31, inclusive
|
||||
* Set the value of the element of the given [array] at the given [index] to
|
||||
* the given [value].
|
||||
*/
|
||||
static int set(int array, int index, bool value) {
|
||||
_checkIndex(index);
|
||||
|
@ -81,21 +67,14 @@ class BooleanArray {
|
|||
|
||||
/**
|
||||
* Set the value of the element at the given index to the given value.
|
||||
*
|
||||
* @param array the array being modified
|
||||
* @param index the index of the element being set
|
||||
* @param value the value to be assigned to the element
|
||||
* @return the updated value of the array
|
||||
* @throws IndexOutOfBoundsException if the index is not between zero (0) and 31, inclusive
|
||||
*/
|
||||
@deprecated
|
||||
static int setEnum(int array, Enum index, bool value) =>
|
||||
set(array, index.ordinal, value);
|
||||
|
||||
/**
|
||||
* Throw an exception if the index is not within the bounds allowed for an integer-encoded array
|
||||
* of boolean values.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if the index is not between zero (0) and 31, inclusive
|
||||
* Throw an exception if the index is not within the bounds allowed for an
|
||||
* integer-encoded array of boolean values.
|
||||
*/
|
||||
static void _checkIndex(int index) {
|
||||
if (index < 0 || index > 30) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import 'package:analyzer/dart/ast/ast.dart' show AnnotatedNode, Comment;
|
|||
import 'package:analyzer/dart/ast/token.dart' show Token;
|
||||
import 'package:analyzer/exception/exception.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart' show ElementImpl;
|
||||
import 'package:analyzer/src/generated/java_core.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/util/fast_uri.dart';
|
||||
|
||||
|
@ -83,11 +82,11 @@ bool startsWith(Uri uri1, Uri uri2) {
|
|||
}
|
||||
|
||||
/**
|
||||
* The enumeration `ParameterKind` defines the different kinds of parameters. There are two
|
||||
* basic kinds of parameters: required and optional. Optional parameters are further divided into
|
||||
* two kinds: positional optional and named optional.
|
||||
* The kinds of a parameter. There are two basic kinds of parameters: required
|
||||
* and optional. Optional parameters are further divided into two kinds:
|
||||
* positional optional and named optional.
|
||||
*/
|
||||
class ParameterKind extends Enum<ParameterKind> {
|
||||
class ParameterKind implements Comparable<ParameterKind> {
|
||||
static const ParameterKind REQUIRED =
|
||||
const ParameterKind('REQUIRED', 0, false);
|
||||
|
||||
|
@ -98,6 +97,16 @@ class ParameterKind extends Enum<ParameterKind> {
|
|||
|
||||
static const List<ParameterKind> values = const [REQUIRED, POSITIONAL, NAMED];
|
||||
|
||||
/**
|
||||
* The name of this parameter.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/**
|
||||
* The ordinal value of the parameter.
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* A flag indicating whether this is an optional parameter.
|
||||
*/
|
||||
|
@ -105,9 +114,15 @@ class ParameterKind extends Enum<ParameterKind> {
|
|||
|
||||
/**
|
||||
* Initialize a newly created kind with the given state.
|
||||
*
|
||||
* @param isOptional `true` if this is an optional parameter
|
||||
*/
|
||||
const ParameterKind(String name, int ordinal, this.isOptional)
|
||||
: super(name, ordinal);
|
||||
const ParameterKind(this.name, this.ordinal, this.isOptional);
|
||||
|
||||
@override
|
||||
int get hashCode => ordinal;
|
||||
|
||||
@override
|
||||
int compareTo(ParameterKind other) => ordinal - other.ordinal;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
|
|
@ -1,210 +0,0 @@
|
|||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
library analyzer.test.enum_test;
|
||||
|
||||
import 'dart:mirrors';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/java_core.dart';
|
||||
import 'package:analyzer/src/generated/resolver.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
initializeTestEnvironment();
|
||||
defineReflectiveTests(EnumTest);
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class EnumTest {
|
||||
void test_AnalysisLevel() {
|
||||
new EnumTester<AnalysisLevel>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_CacheState() {
|
||||
new EnumTester<CacheState>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_ElementKind() {
|
||||
new EnumTester<ElementKind>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_ErrorProperty() {
|
||||
new EnumTester<ErrorProperty>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_ErrorSeverity() {
|
||||
new EnumTester<ErrorSeverity>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_ErrorType() {
|
||||
new EnumTester<ErrorType>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_INIT_STATE() {
|
||||
new EnumTester<INIT_STATE>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_Modifier() {
|
||||
new EnumTester<Modifier>(
|
||||
ignoreGetters: ["persistedValues", "transientValues"])
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_ParameterKind() {
|
||||
new EnumTester<ParameterKind>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_RedirectingConstructorKind() {
|
||||
new EnumTester<RedirectingConstructorKind>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_SourceKind() {
|
||||
new EnumTester<SourceKind>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
|
||||
void test_UriKind() {
|
||||
new EnumTester<UriKind>()
|
||||
..check_getters()
|
||||
..check_explicit_values();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for testing invariants of enumerated types.
|
||||
*/
|
||||
class EnumTester<C extends Enum> {
|
||||
/**
|
||||
* Set of getter names which should be ignored when looking for getters
|
||||
* representing enum values.
|
||||
*/
|
||||
Set<String> _ignoreGetters = new Set<String>();
|
||||
|
||||
EnumTester({List<String> ignoreGetters}) {
|
||||
// Always ignore a getter called "values".
|
||||
_ignoreGetters.add('values');
|
||||
|
||||
if (ignoreGetters != null) {
|
||||
for (String getterName in ignoreGetters) {
|
||||
_ignoreGetters.add(getterName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a map from getter name to the value returned by the getter, for all
|
||||
* static getters in [C] whose name isn't in [_ignoreGetters].
|
||||
*/
|
||||
Map<String, C> get _getters {
|
||||
Map<String, C> result = <String, C>{};
|
||||
ClassMirror reflectedClass = reflectClass(C);
|
||||
reflectedClass.staticMembers.forEach((Symbol symbol, MethodMirror method) {
|
||||
if (!method.isGetter) {
|
||||
return;
|
||||
}
|
||||
String name = MirrorSystem.getName(symbol);
|
||||
if (_ignoreGetters.contains(name)) {
|
||||
return;
|
||||
}
|
||||
C value = reflectedClass.getField(symbol).reflectee as C;
|
||||
result[name] = value;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invariants on the list of enum values accessible via the static
|
||||
* getter "values".
|
||||
*/
|
||||
void check_explicit_values() {
|
||||
ClassMirror reflectedClass = reflectClass(C);
|
||||
List<C> values = reflectedClass.getField(#values).reflectee as List<C>;
|
||||
Map<C, int> reverseMap = <C, int>{};
|
||||
|
||||
// Check that "values" is a list of values of type C, with no duplicates.
|
||||
expect(values, isList);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
C value = values[i];
|
||||
expect(value, new isInstanceOf<C>(), reason: 'values[$i]');
|
||||
if (reverseMap.containsKey(value)) {
|
||||
fail('values[$i] and values[${reverseMap[value]}] both equal $value');
|
||||
}
|
||||
reverseMap[value] = i;
|
||||
}
|
||||
|
||||
// Check that the set of values in the "values" list matches the set of
|
||||
// values accessible via static fields.
|
||||
expect(reverseMap.keys.toSet(), equals(_getters.values.toSet()));
|
||||
|
||||
// Make sure the order of the list matches the ordinal numbers.
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
expect(values[i].ordinal, equals(i), reason: 'values[$i].ordinal');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invariants on the set of enum values accessible via the static
|
||||
* getters defined in the class [C] (with the exception of a getter called
|
||||
* "values").
|
||||
*/
|
||||
void check_getters() {
|
||||
Map<int, String> ordinals = <int, String>{};
|
||||
int numValues = 0;
|
||||
|
||||
_getters.forEach((String name, C value) {
|
||||
String reason = 'getter: $name';
|
||||
++numValues;
|
||||
|
||||
// Check the type of the value
|
||||
expect(value, new isInstanceOf<C>(), reason: reason);
|
||||
|
||||
// Check that the name of the getter matches the name stored in the enum.
|
||||
expect(value.name, equals(name), reason: reason);
|
||||
|
||||
// Check that there are no duplicate ordinals.
|
||||
if (ordinals.containsKey(value.ordinal)) {
|
||||
fail(
|
||||
'Getters $name and ${ordinals[value.ordinal]} have ordinal value ${value.ordinal}');
|
||||
}
|
||||
ordinals[value.ordinal] = name;
|
||||
});
|
||||
|
||||
// Check that the set of ordinals runs from 0 to N-1, where N is the number
|
||||
// of enumerated values.
|
||||
Set<int> expectedOrdinals = new Set<int>();
|
||||
for (int i = 0; i < numValues; i++) {
|
||||
expectedOrdinals.add(i);
|
||||
}
|
||||
expect(ordinals.keys.toSet(), equals(expectedOrdinals));
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ import 'package:unittest/unittest.dart';
|
|||
|
||||
import 'cancelable_future_test.dart' as cancelable_future_test;
|
||||
import 'context/test_all.dart' as context;
|
||||
import 'enum_test.dart' as enum_test;
|
||||
import 'file_system/test_all.dart' as file_system;
|
||||
import 'generated/test_all.dart' as generated;
|
||||
import 'instrumentation/test_all.dart' as instrumentation;
|
||||
|
@ -23,7 +22,6 @@ main() {
|
|||
group('analysis engine', () {
|
||||
cancelable_future_test.main();
|
||||
context.main();
|
||||
enum_test.main();
|
||||
file_system.main();
|
||||
generated.main();
|
||||
instrumentation.main();
|
||||
|
|
Loading…
Reference in a new issue