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

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

Issue 289003003: Fix remaining RequestDatum tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | pkg/analysis_server/test/protocol_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 5cdb3af81ff898c99aa6f425b8443e214227b1e1..75b29c7a60be4825563fd3b48fe0d764e371049a 100644
--- a/pkg/analysis_server/lib/src/protocol.dart
+++ b/pkg/analysis_server/lib/src/protocol.dart
@@ -173,7 +173,7 @@ class RequestDatum {
* a [RequestDatum] containing the corresponding value.
*/
RequestDatum operator [](String key) {
- if (datum is! Map<String, dynamic>) {
+ if (datum is! Map) {
throw new RequestFailure(new Response.invalidParameter(request, path,
"be a map"));
}
@@ -188,7 +188,7 @@ class RequestDatum {
* Return `true` if the datum is a Map containing the given [key].
*/
bool hasKey(String key) {
- if (datum is! Map<String, dynamic>) {
+ if (datum is! Map) {
throw new RequestFailure(new Response.invalidParameter(request, path,
"be a map"));
}
@@ -200,7 +200,7 @@ class RequestDatum {
* each key/value pair in the map.
*/
void forEachMap(void f(String key, RequestDatum value)) {
- if (datum is! Map<String, dynamic>) {
+ if (datum is! Map) {
throw new RequestFailure(new Response.invalidParameter(request, path,
"be a map"));
}
@@ -257,10 +257,25 @@ class RequestDatum {
}
/**
+ * Determine if the datum is a list of strings.
+ */
+ bool isStringList() {
+ if (datum is! List) {
+ return false;
+ }
+ for (var element in datum) {
+ if (element is! String) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Validate that the datum is a list of strings, and return it.
*/
List<String> asStringList() {
- if (datum is! List<String>) {
+ if (!isStringList()) {
throw new RequestFailure(new Response.invalidParameter(request, path,
"be a list of strings"));
}
@@ -268,10 +283,28 @@ class RequestDatum {
}
/**
+ * 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
+ * cannot have any other key type.
+ */
+ bool isStringMap() {
+ if (datum is! Map) {
+ return false;
+ }
+ for (var value in datum.values) {
+ if (value is! String) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Validate that the datum is a map from strings to strings, and return it.
*/
Map<String, String> asStringMap() {
- if (datum is! Map<String, String>) {
+ if (!isStringMap()) {
throw new RequestFailure(new Response.invalidParameter(request, path,
"be a string map"));
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/protocol_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698