| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import 'dart:convert' hide JsonDecoder; | 6 import 'dart:convert' hide JsonDecoder; |
| 7 | 7 |
| 8 import 'package:analyzer_plugin/protocol/protocol.dart'; | 8 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 10 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Translate the input [map], applying [keyCallback] to all its keys, and | 131 * Translate the input [map], applying [keyCallback] to all its keys, and |
| 132 * [valueCallback] to all its values. | 132 * [valueCallback] to all its values. |
| 133 */ | 133 */ |
| 134 Map/*<KR, VR>*/ mapMap/*<KP, VP, KR, VR>*/(Map/*<KP, VP>*/ map, | 134 Map<KR, VR> mapMap<KP, VP, KR, VR>(Map<KP, VP> map, |
| 135 {dynamic/*=KR*/ keyCallback(/*<KP>*/ key), | 135 {KR keyCallback(KP key), VR valueCallback(VP value)}) { |
| 136 dynamic/*=VR*/ valueCallback(/*<VP>*/ value)}) { | 136 Map<KR, VR> result = new HashMap<KR, VR>(); |
| 137 Map/*<KR, VR>*/ result = new HashMap/*<KR, VR>*/(); | |
| 138 map.forEach((key, value) { | 137 map.forEach((key, value) { |
| 139 Object/*=KR*/ resultKey; | 138 KR resultKey; |
| 140 Object/*=VR*/ resultValue; | 139 VR resultValue; |
| 141 if (keyCallback != null) { | 140 if (keyCallback != null) { |
| 142 resultKey = keyCallback(key); | 141 resultKey = keyCallback(key); |
| 143 } else { | 142 } else { |
| 144 resultKey = key as Object/*=KR*/; | 143 resultKey = key as KR; |
| 145 } | 144 } |
| 146 if (valueCallback != null) { | 145 if (valueCallback != null) { |
| 147 resultValue = valueCallback(value); | 146 resultValue = valueCallback(value); |
| 148 } else { | 147 } else { |
| 149 resultValue = value as Object/*=VR*/; | 148 resultValue = value as VR; |
| 150 } | 149 } |
| 151 result[resultKey] = resultValue; | 150 result[resultKey] = resultValue; |
| 152 }); | 151 }); |
| 153 return result; | 152 return result; |
| 154 } | 153 } |
| 155 | 154 |
| 156 RefactoringProblemSeverity maxRefactoringProblemSeverity( | 155 RefactoringProblemSeverity maxRefactoringProblemSeverity( |
| 157 RefactoringProblemSeverity a, RefactoringProblemSeverity b) { | 156 RefactoringProblemSeverity a, RefactoringProblemSeverity b) { |
| 158 if (b == null) { | 157 if (b == null) { |
| 159 return a; | 158 return a; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 217 } |
| 219 if (kind == RefactoringKind.MOVE_FILE) { | 218 if (kind == RefactoringKind.MOVE_FILE) { |
| 220 return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json); | 219 return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json); |
| 221 } | 220 } |
| 222 if (kind == RefactoringKind.RENAME) { | 221 if (kind == RefactoringKind.RENAME) { |
| 223 return new RenameOptions.fromJson(jsonDecoder, jsonPath, json); | 222 return new RenameOptions.fromJson(jsonDecoder, jsonPath, json); |
| 224 } | 223 } |
| 225 return null; | 224 return null; |
| 226 } | 225 } |
| 227 | 226 |
| 228 ///** | |
| 229 // * Create a [RefactoringFeedback] corresponding the given [kind]. | |
| 230 // */ | |
| 231 //RefactoringFeedback refactoringFeedbackFromJson( | |
| 232 // JsonDecoder jsonDecoder, String jsonPath, Object json, Map feedbackJson) { | |
| 233 // RefactoringKind kind = jsonDecoder.refactoringKind; | |
| 234 // if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | |
| 235 // return new ExtractLocalVariableFeedback.fromJson( | |
| 236 // jsonDecoder, jsonPath, json); | |
| 237 // } | |
| 238 // if (kind == RefactoringKind.EXTRACT_METHOD) { | |
| 239 // return new ExtractMethodFeedback.fromJson(jsonDecoder, jsonPath, json); | |
| 240 // } | |
| 241 // if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { | |
| 242 // return new InlineLocalVariableFeedback.fromJson( | |
| 243 // jsonDecoder, jsonPath, json); | |
| 244 // } | |
| 245 // if (kind == RefactoringKind.INLINE_METHOD) { | |
| 246 // return new InlineMethodFeedback.fromJson(jsonDecoder, jsonPath, json); | |
| 247 // } | |
| 248 // if (kind == RefactoringKind.RENAME) { | |
| 249 // return new RenameFeedback.fromJson(jsonDecoder, jsonPath, json); | |
| 250 // } | |
| 251 // return null; | |
| 252 //} | |
| 253 // | |
| 254 ///** | |
| 255 // * Create a [RefactoringOptions] corresponding the given [kind]. | |
| 256 // */ | |
| 257 //RefactoringOptions refactoringOptionsFromJson(JsonDecoder jsonDecoder, | |
| 258 // String jsonPath, Object json, RefactoringKind kind) { | |
| 259 // if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | |
| 260 // return new ExtractLocalVariableOptions.fromJson( | |
| 261 // jsonDecoder, jsonPath, json); | |
| 262 // } | |
| 263 // if (kind == RefactoringKind.EXTRACT_METHOD) { | |
| 264 // return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json); | |
| 265 // } | |
| 266 // if (kind == RefactoringKind.INLINE_METHOD) { | |
| 267 // return new InlineMethodOptions.fromJson(jsonDecoder, jsonPath, json); | |
| 268 // } | |
| 269 // if (kind == RefactoringKind.MOVE_FILE) { | |
| 270 // return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json); | |
| 271 // } | |
| 272 // if (kind == RefactoringKind.RENAME) { | |
| 273 // return new RenameOptions.fromJson(jsonDecoder, jsonPath, json); | |
| 274 // } | |
| 275 // return null; | |
| 276 //} | |
| 277 | |
| 278 /** | 227 /** |
| 279 * Type of callbacks used to decode parts of JSON objects. [jsonPath] is a | 228 * Type of callbacks used to decode parts of JSON objects. [jsonPath] is a |
| 280 * string describing the part of the JSON object being decoded, and [value] is | 229 * string describing the part of the JSON object being decoded, and [value] is |
| 281 * the part to decode. | 230 * the part to decode. |
| 282 */ | 231 */ |
| 283 typedef E JsonDecoderCallback<E>(String jsonPath, Object value); | 232 typedef E JsonDecoderCallback<E>(String jsonPath, Object value); |
| 284 | 233 |
| 285 /** | 234 /** |
| 286 * Instances of the class [HasToJson] implement [toJson] method that returns | 235 * Instances of the class [HasToJson] implement [toJson] method that returns |
| 287 * a JSON presentation. | 236 * a JSON presentation. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 283 } |
| 335 throw mismatch(jsonPath, 'int', json); | 284 throw mismatch(jsonPath, 'int', json); |
| 336 } | 285 } |
| 337 | 286 |
| 338 /** | 287 /** |
| 339 * Decode a JSON object that is expected to be a List. The [decoder] is used | 288 * Decode a JSON object that is expected to be a List. The [decoder] is used |
| 340 * to decode the items in the list. | 289 * to decode the items in the list. |
| 341 * | 290 * |
| 342 * The type parameter [E] is the expected type of the elements in the list. | 291 * The type parameter [E] is the expected type of the elements in the list. |
| 343 */ | 292 */ |
| 344 List/*<E>*/ decodeList/*<E>*/(String jsonPath, Object json, | 293 List<E> decodeList<E>(String jsonPath, Object json, |
| 345 [JsonDecoderCallback/*<E>*/ decoder]) { | 294 [JsonDecoderCallback<E> decoder]) { |
| 346 if (json == null) { | 295 if (json == null) { |
| 347 return/*<E>*/ []; | 296 return <E>[]; |
| 348 } else if (json is List) { | 297 } else if (json is List) { |
| 349 List/*<E>*/ result = /*<E>*/ []; | 298 List<E> result = <E>[]; |
| 350 for (int i = 0; i < json.length; i++) { | 299 for (int i = 0; i < json.length; i++) { |
| 351 result.add(decoder('$jsonPath[$i]', json[i])); | 300 result.add(decoder('$jsonPath[$i]', json[i])); |
| 352 } | 301 } |
| 353 return result; | 302 return result; |
| 354 } else { | 303 } else { |
| 355 throw mismatch(jsonPath, 'List', json); | 304 throw mismatch(jsonPath, 'List', json); |
| 356 } | 305 } |
| 357 } | 306 } |
| 358 | 307 |
| 359 /** | 308 /** |
| 360 * Decode a JSON object that is expected to be a Map. [keyDecoder] is used | 309 * Decode a JSON object that is expected to be a Map. [keyDecoder] is used |
| 361 * to decode the keys, and [valueDecoder] is used to decode the values. | 310 * to decode the keys, and [valueDecoder] is used to decode the values. |
| 362 */ | 311 */ |
| 363 Map/*<K, V>*/ decodeMap/*<K, V>*/(String jsonPath, Object json, | 312 Map<K, V> decodeMap<K, V>(String jsonPath, Object json, |
| 364 {JsonDecoderCallback/*<K>*/ keyDecoder, | 313 {JsonDecoderCallback<K> keyDecoder, |
| 365 JsonDecoderCallback/*<V>*/ valueDecoder}) { | 314 JsonDecoderCallback<V> valueDecoder}) { |
| 366 if (json == null) { | 315 if (json == null) { |
| 367 return {}; | 316 return {}; |
| 368 } else if (json is Map) { | 317 } else if (json is Map) { |
| 369 Map/*<K, V>*/ result = /*<K, V>*/ {}; | 318 Map<K, V> result = <K, V>{}; |
| 370 json.forEach((String key, value) { | 319 json.forEach((String key, value) { |
| 371 Object/*=K*/ decodedKey; | 320 K decodedKey; |
| 372 if (keyDecoder != null) { | 321 if (keyDecoder != null) { |
| 373 decodedKey = keyDecoder('$jsonPath.key', key); | 322 decodedKey = keyDecoder('$jsonPath.key', key); |
| 374 } else { | 323 } else { |
| 375 decodedKey = key as Object/*=K*/; | 324 decodedKey = key as K; |
| 376 } | 325 } |
| 377 if (valueDecoder != null) { | 326 if (valueDecoder != null) { |
| 378 value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value); | 327 value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value); |
| 379 } | 328 } |
| 380 result[decodedKey] = value as Object/*=V*/; | 329 result[decodedKey] = value as V; |
| 381 }); | 330 }); |
| 382 return result; | 331 return result; |
| 383 } else { | 332 } else { |
| 384 throw mismatch(jsonPath, 'Map', json); | 333 throw mismatch(jsonPath, 'Map', json); |
| 385 } | 334 } |
| 386 } | 335 } |
| 387 | 336 |
| 388 /** | 337 /** |
| 389 * Decode a JSON object that is expected to be a string. | 338 * Decode a JSON object that is expected to be a string. |
| 390 */ | 339 */ |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 /** | 463 /** |
| 515 * The result data associated with a response. | 464 * The result data associated with a response. |
| 516 */ | 465 */ |
| 517 abstract class ResponseResult implements HasToJson { | 466 abstract class ResponseResult implements HasToJson { |
| 518 /** | 467 /** |
| 519 * Return a response whose result data is this object for the request with the | 468 * Return a response whose result data is this object for the request with the |
| 520 * given [id], where the request was received at the given [requestTime]. | 469 * given [id], where the request was received at the given [requestTime]. |
| 521 */ | 470 */ |
| 522 Response toResponse(String id, int requestTime); | 471 Response toResponse(String id, int requestTime); |
| 523 } | 472 } |
| OLD | NEW |