Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 297153002: Implementation of 'Server Domain' in dart analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More fixes for comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/domain_server.dart ('k') | pkg/analysis_server/test/analysis_server_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « pkg/analysis_server/lib/src/domain_server.dart ('k') | pkg/analysis_server/test/analysis_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698