| 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..33628b1e46090aa01d5ca75fbd65d249c307d5a5 100644
|
| --- a/pkg/analysis_server/lib/src/protocol.dart
|
| +++ b/pkg/analysis_server/lib/src/protocol.dart
|
| @@ -7,6 +7,45 @@ 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);
|
| +
|
| + @override
|
| + int get hashCode => ordinal;
|
| +
|
| + @override
|
| + 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 (int i = 0; i < values.length; i++) {
|
| + Enum2 value = values[i];
|
| + if (value.name == name) {
|
| + return value;
|
| + }
|
| + }
|
| + return null;
|
| + }
|
| +}
|
| +
|
| +
|
| +/**
|
| * Instances of the class [Request] represent a request that was received.
|
| */
|
| class Request {
|
| @@ -283,6 +322,22 @@ class RequestDatum {
|
| }
|
|
|
| /**
|
| + * Validate that the datum is a list of strings, and convert it into [Enum]s.
|
| + */
|
| + Set<Enum2> asEnumSet(List<Enum2> allValues) {
|
| + Set values = new Set();
|
| + for (String name in asStringList()) {
|
| + Enum2 value = Enum2.valueOf(allValues, name);
|
| + if (value == null) {
|
| + throw new RequestFailure(new Response.invalidParameter(request, path,
|
| + "be a list of names from the list $allValues"));
|
| + }
|
| + 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
|
|
|