Chromium Code Reviews| Index: pkg/analysis_server/lib/src/protocol.dart |
| diff --git a/pkg/analysis_server/lib/src/protocol.dart b/pkg/analysis_server/lib/src/protocol.dart |
| index 75b29c7a60be4825563fd3b48fe0d764e371049a..52836205858ac5f0382a166ecce5d8c3a5362b0a 100644 |
| --- a/pkg/analysis_server/lib/src/protocol.dart |
| +++ b/pkg/analysis_server/lib/src/protocol.dart |
| @@ -6,6 +6,34 @@ library protocol; |
| import 'dart:convert' show JsonDecoder; |
| +/// An abstract enumeration. |
| +abstract class Enum2<E extends Enum2> implements Comparable<E> { |
| + /// The name of this enum constant, as declared in the enum declaration. |
| + final String name; |
| + |
| + /// The position in the enum declaration. |
| + final int ordinal; |
| + |
| + const Enum2(this.name, this.ordinal); |
| + |
| + int get hashCode => ordinal; |
| + |
| + String toString() => name; |
| + |
| + int compareTo(E other) => ordinal - other.ordinal; |
| + |
| + /// Returns the enum constant with the given [name], `null` if not found. |
| + static Enum2 valueOf(List<Enum2> values, String name) { |
| + for (var e in values) { |
|
Brian Wilkerson
2014/05/24 15:19:49
The body of the method should be indented.
We sho
scheglov
2014/05/24 15:34:42
Done.
|
| + if (e.name == name) { |
| + return e; |
| + } |
| + } |
| + return null; |
| + } |
| +} |
| + |
| + |
| /** |
| * Instances of the class [Request] represent a request that was received. |
| */ |
| @@ -283,6 +311,22 @@ class RequestDatum { |
| } |
| /** |
| + * Validate that the datum is a list of strings, and convert it into [Enum]s. |
| + */ |
| + Set<Enum2> asEnumSet(List<Enum2> allValues) { |
| + var values = new Set(); |
| + for (var name in asStringList()) { |
| + var value = Enum2.valueOf(allValues, name); |
| + if (value == null) { |
| + throw new RequestFailure(new Response.invalidParameter(request, path, |
| + "be a list of names the enumeration values $allValues")); |
|
Brian Wilkerson
2014/05/24 15:19:49
"names the enumeration values" --> "names from the
scheglov
2014/05/24 15:34:42
Done.
|
| + } |
| + values.add(value); |
| + } |
| + return values; |
| + } |
| + |
| + /** |
| * Determine if the datum is a map whose values are all strings. |
| * |
| * Note: we can safely assume that the keys are all strings, since JSON maps |