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

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

Issue 1849973002: Fix the way generated code is made strong mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Make JsonDecoderCallback generic Created 4 years, 9 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
Index: pkg/analysis_server/lib/src/protocol/protocol_internal.dart
diff --git a/pkg/analysis_server/lib/src/protocol/protocol_internal.dart b/pkg/analysis_server/lib/src/protocol/protocol_internal.dart
index 256523abf7c32a2bb9b529cc54f8c3b7ffd50071..ce774edd9971ab19916738b481201917dc50057b 100644
--- a/pkg/analysis_server/lib/src/protocol/protocol_internal.dart
+++ b/pkg/analysis_server/lib/src/protocol/protocol_internal.dart
@@ -222,7 +222,7 @@ RefactoringOptions refactoringOptionsFromJson(JsonDecoder jsonDecoder,
* string describing the part of the JSON object being decoded, and [value] is
* the part to decode.
*/
-typedef Object JsonDecoderCallback(String jsonPath, Object value);
+typedef E JsonDecoderCallback<E>(String jsonPath, Object value);
/**
* Instances of the class [HasToJson] implement [toJson] method that returns
@@ -303,14 +303,17 @@ abstract class JsonDecoder {
}
/**
- * Decode a JSON object that is expected to be a List. [decoder] is used to
- * decode the items in the list.
+ * Decode a JSON object that is expected to be a List. The [decoder] is used
+ * to decode the items in the list.
+ *
+ * The type parameter [E] is the expected type of the elements in the list.
*/
- List decodeList(String jsonPath, Object json, [JsonDecoderCallback decoder]) {
+ List/*<E>*/ decodeList/*<E>*/(String jsonPath, Object json,
+ [JsonDecoderCallback/*<E>*/ decoder]) {
if (json == null) {
- return [];
+ return/*<E>*/ [];
} else if (json is List) {
- List result = [];
+ List/*<E>*/ result = /*<E>*/ [];
for (int i = 0; i < json.length; i++) {
result.add(decoder('$jsonPath[$i]', json[i]));
}
@@ -324,23 +327,24 @@ abstract class JsonDecoder {
* Decode a JSON object that is expected to be a Map. [keyDecoder] is used
* to decode the keys, and [valueDecoder] is used to decode the values.
*/
- Map decodeMap(String jsonPath, Object json,
- {JsonDecoderCallback keyDecoder, JsonDecoderCallback valueDecoder}) {
+ Map/*<K, V>*/ decodeMap/*<K, V>*/(String jsonPath, Object json,
+ {JsonDecoderCallback/*<K>*/ keyDecoder,
+ JsonDecoderCallback/*<V>*/ valueDecoder}) {
if (json == null) {
return {};
} else if (json is Map) {
- Map result = {};
+ Map/*<K, V>*/ result = /*<K, V>*/ {};
json.forEach((String key, value) {
- Object decodedKey;
+ Object/*=K*/ decodedKey;
if (keyDecoder != null) {
decodedKey = keyDecoder('$jsonPath.key', key);
} else {
- decodedKey = key;
+ decodedKey = key as Object/*=K*/;
}
if (valueDecoder != null) {
value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value);
}
- result[decodedKey] = value;
+ result[decodedKey] = value as Object/*=V*/;
});
return result;
} else {

Powered by Google App Engine
This is Rietveld 408576698