| 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 f0cd4d8c47fcb609bf4e18857f8a21ea1cc4bd9f..55b81728de9e4f3e8c2ca0dc7eb4174b3ebf2417 100644
|
| --- a/pkg/analysis_server/lib/src/protocol.dart
|
| +++ b/pkg/analysis_server/lib/src/protocol.dart
|
| @@ -95,18 +95,6 @@ class Request {
|
| }
|
|
|
| /**
|
| - * Return the value of the parameter with the given [name], or throw a
|
| - * [RequestFailure] exception with an appropriate error message if there is no
|
| - * such parameter associated with this request.
|
| - */
|
| - RequestDatum getRequiredParameter(String name) {
|
| - if (!params.containsKey(name)) {
|
| - throw new RequestFailure(new Response.missingRequiredParameter(this, name));
|
| - }
|
| - return new RequestDatum(this, name, params[name]);
|
| - }
|
| -
|
| - /**
|
| * Return a table representing the structure of the Json object that will be
|
| * sent to the client to represent this response.
|
| */
|
| @@ -122,272 +110,6 @@ class Request {
|
| }
|
|
|
| /**
|
| - * Instances of the class [RequestDatum] wrap a piece of data from a
|
| - * request parameter, and contain accessor methods which automatically validate
|
| - * and convert the data into the appropriate form.
|
| - */
|
| -class RequestDatum {
|
| - /**
|
| - * Request object that should be referred to in any errors that are
|
| - * generated.
|
| - */
|
| - final Request request;
|
| -
|
| - /**
|
| - * String description of how [datum] was obtained from the request.
|
| - */
|
| - final String path;
|
| -
|
| - /**
|
| - * Value to be decoded and validated.
|
| - */
|
| - final dynamic datum;
|
| -
|
| - /**
|
| - * Create a RequestDatum for decoding and validating [datum], which refers to
|
| - * [request] in any errors it reports.
|
| - */
|
| - RequestDatum(this.request, this.path, this.datum);
|
| -
|
| - /**
|
| - * Validate that the datum is a Map containing the given [key], and return
|
| - * a [RequestDatum] containing the corresponding value.
|
| - */
|
| - RequestDatum operator [](String key) {
|
| - Map<String, Object> map = _asMap();
|
| - if (!map.containsKey(key)) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "contain key '$key'"));
|
| - }
|
| - return new RequestDatum(request, "$path.$key", map[key]);
|
| - }
|
| -
|
| - /**
|
| - * Return `true` if the datum is a Map containing the given [key].
|
| - */
|
| - bool hasKey(String key) {
|
| - return _asMap().containsKey(key);
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a Map, and return an iterable for its keys.
|
| - */
|
| - Iterable<String> get keys => _asMap().keys;
|
| -
|
| - /**
|
| - * Validate that the datum is a Map whose keys are strings, and call [f] on
|
| - * each key/value pair in the map.
|
| - */
|
| - void forEachMap(void f(String key, RequestDatum value)) {
|
| - _asMap().forEach((String key, value) {
|
| - f(key, new RequestDatum(request, "$path.$key", value));
|
| - });
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is an integer (or a string that can be parsed
|
| - * as an integer), and return the int.
|
| - */
|
| - int asInt() {
|
| - if (datum is int) {
|
| - return datum;
|
| - } else if (datum is String) {
|
| - return int.parse(datum, onError: (String value) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be an integer"));
|
| - });
|
| - }
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be an integer"));
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a boolean (or a string that can be parsed
|
| - * as a boolean), and return the bool.
|
| - *
|
| - * The value is typically the result of invoking either [getParameter] or
|
| - * [getRequiredParameter].
|
| - */
|
| - bool asBool() {
|
| - if (datum is bool) {
|
| - return datum;
|
| - } else if (datum == 'true') {
|
| - return true;
|
| - } else if (datum == 'false') {
|
| - return false;
|
| - }
|
| - throw new RequestFailure(new Response.invalidParameter(request, datum,
|
| - "be a boolean"));
|
| - }
|
| -
|
| - /**
|
| - * Determine if the datum is a list. Note: null is considered a synonym for
|
| - * the empty list.
|
| - */
|
| - bool get isList {
|
| - return datum == null || datum is List;
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a list, and return it in raw form.
|
| - */
|
| - List _asList() {
|
| - if (!isList) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a list"));
|
| - }
|
| - if (datum == null) {
|
| - return [];
|
| - } else {
|
| - return datum;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a list, and return a list where each element in
|
| - * the datum has been converted using the provided function.
|
| - */
|
| - List asList(elementConverter(RequestDatum datum)) {
|
| - List result = [];
|
| - List list = _asList();
|
| - for (int i = 0; i < list.length; i++) {
|
| - result.add(elementConverter(new RequestDatum(request, "$path.$i", list[i])));
|
| - }
|
| - return result;
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a string, and return it.
|
| - */
|
| - String asString() {
|
| - if (datum is! String) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a string"));
|
| - }
|
| - return datum;
|
| - }
|
| -
|
| - /**
|
| - * Determine if the datum is a list of strings. Note: null is considered a
|
| - * synonym for the empty list.
|
| - */
|
| - bool get isStringList {
|
| - if (!isList) {
|
| - return false;
|
| - }
|
| - for (var element in _asList()) {
|
| - if (element is! String) {
|
| - return false;
|
| - }
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a list of strings, and return it. Note: null
|
| - * is considered a synonym for the empty list.
|
| - */
|
| - List<String> asStringList() {
|
| - if (!isStringList) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a list of strings"));
|
| - }
|
| - return _asList();
|
| - }
|
| -
|
| - /**
|
| - * Determine if the datum is a map. Note: null is considered a synonym for
|
| - * the empty map.
|
| - */
|
| - bool get isMap {
|
| - return datum == null || datum is Map;
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a map, and return it in raw form.
|
| - */
|
| - Map<String, Object> _asMap() {
|
| - if (!isMap) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a map"));
|
| - }
|
| - if (datum == null) {
|
| - return {};
|
| - } else {
|
| - return datum;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Determine if the datum is a map whose values are all strings. Note: null
|
| - * is considered a synonym for the empty map.
|
| - *
|
| - * Note: we can safely assume that the keys are all strings, since JSON maps
|
| - * cannot have any other key type.
|
| - */
|
| - bool get isStringMap {
|
| - if (!isMap) {
|
| - return false;
|
| - }
|
| - for (var value in _asMap().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 (!isStringMap) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a string map"));
|
| - }
|
| - return _asMap();
|
| - }
|
| -
|
| - /**
|
| - * Determine if the datum is a map whose values are all string lists. Note:
|
| - * null is considered a synonym for the empty map.
|
| - *
|
| - * Note: we can safely assume that the keys are all strings, since JSON maps
|
| - * cannot have any other key type.
|
| - */
|
| - bool get isStringListMap {
|
| - if (!isMap) {
|
| - return false;
|
| - }
|
| - for (var value in _asMap().values) {
|
| - if (value is! List) {
|
| - return false;
|
| - }
|
| - for (var listItem in value) {
|
| - if (listItem is! String) {
|
| - return false;
|
| - }
|
| - }
|
| - }
|
| - return true;
|
| - }
|
| -
|
| - /**
|
| - * Validate that the datum is a map from strings to string lists, and return
|
| - * it.
|
| - */
|
| - Map<String, List<String>> asStringListMap() {
|
| - if (!isStringListMap) {
|
| - throw new RequestFailure(new Response.invalidParameter(request, path,
|
| - "be a string list map"));
|
| - }
|
| - return _asMap();
|
| - }
|
| -
|
| - bool get isNull => datum == null;
|
| -}
|
| -
|
| -/**
|
| * Instances of the class [Response] represent a response to a request.
|
| */
|
| class Response {
|
| @@ -553,13 +275,6 @@ class Response {
|
| }
|
|
|
| /**
|
| - * Return the value of the result field with the given [name].
|
| - */
|
| - Object getResult(String name) {
|
| - return result == null ? null : result[name];
|
| - }
|
| -
|
| - /**
|
| * Set the value of the result field with the given [name] to the given [value].
|
| */
|
| void setResult(String name, Object value) {
|
|
|