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:convert'; | 5 import 'dart:convert'; |
6 | 6 |
7 import 'package:analyzer/src/codegen/tools.dart'; | 7 import 'package:analyzer/src/codegen/tools.dart'; |
8 import 'package:html/dom.dart' as dom; | 8 import 'package:html/dom.dart' as dom; |
9 | 9 |
10 import 'api.dart'; | 10 import 'api.dart'; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 }); | 216 }); |
217 toHtmlVisitor.p(() { | 217 toHtmlVisitor.p(() { |
218 toHtmlVisitor.write(disclaimer); | 218 toHtmlVisitor.write(disclaimer); |
219 }); | 219 }); |
220 })); | 220 })); |
221 write('class $className'); | 221 write('class $className'); |
222 if (impliedType.kind == 'refactoringFeedback') { | 222 if (impliedType.kind == 'refactoringFeedback') { |
223 writeln(' extends RefactoringFeedback implements HasToJson {'); | 223 writeln(' extends RefactoringFeedback implements HasToJson {'); |
224 } else if (impliedType.kind == 'refactoringOptions') { | 224 } else if (impliedType.kind == 'refactoringOptions') { |
225 writeln(' extends RefactoringOptions implements HasToJson {'); | 225 writeln(' extends RefactoringOptions implements HasToJson {'); |
| 226 } else if (impliedType.kind == 'requestParams') { |
| 227 writeln(' implements RequestParams {'); |
226 } else if (impliedType.kind == 'requestResult') { | 228 } else if (impliedType.kind == 'requestResult') { |
227 writeln(' implements ResponseResult {'); | 229 writeln(' implements ResponseResult {'); |
228 } else { | 230 } else { |
229 writeln(' {'); | 231 writeln(' {'); |
230 } | 232 } |
231 indent(() { | 233 indent(() { |
232 if (impliedType.kind == 'requestResult') { | 234 if (impliedType.kind == 'requestResult' || |
| 235 impliedType.kind == 'requestParams') { |
233 emitEmptyToJsonMember(); | 236 emitEmptyToJsonMember(); |
234 writeln(); | 237 writeln(); |
235 } | 238 } |
236 if (emitToRequestMember(impliedType)) { | 239 if (emitToRequestMember(impliedType)) { |
237 writeln(); | 240 writeln(); |
238 } | 241 } |
239 if (emitToResponseMember(impliedType)) { | 242 if (emitToResponseMember(impliedType)) { |
240 writeln(); | 243 writeln(); |
241 } | 244 } |
242 if (emitToNotificationMember(impliedType)) { | 245 if (emitToNotificationMember(impliedType)) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 401 } |
399 toHtmlVisitor.p(() { | 402 toHtmlVisitor.p(() { |
400 toHtmlVisitor.write(disclaimer); | 403 toHtmlVisitor.write(disclaimer); |
401 }); | 404 }); |
402 })); | 405 })); |
403 write('class $className'); | 406 write('class $className'); |
404 if (impliedType.kind == 'refactoringFeedback') { | 407 if (impliedType.kind == 'refactoringFeedback') { |
405 writeln(' extends RefactoringFeedback {'); | 408 writeln(' extends RefactoringFeedback {'); |
406 } else if (impliedType.kind == 'refactoringOptions') { | 409 } else if (impliedType.kind == 'refactoringOptions') { |
407 writeln(' extends RefactoringOptions {'); | 410 writeln(' extends RefactoringOptions {'); |
| 411 } else if (impliedType.kind == 'requestParams') { |
| 412 writeln(' implements RequestParams {'); |
408 } else if (impliedType.kind == 'requestResult') { | 413 } else if (impliedType.kind == 'requestResult') { |
409 writeln(' implements ResponseResult {'); | 414 writeln(' implements ResponseResult {'); |
410 } else { | 415 } else { |
411 writeln(' implements HasToJson {'); | 416 writeln(' implements HasToJson {'); |
412 } | 417 } |
413 indent(() { | 418 indent(() { |
414 if (emitSpecialStaticMembers(className)) { | 419 if (emitSpecialStaticMembers(className)) { |
415 writeln(); | 420 writeln(); |
416 } | 421 } |
417 for (TypeObjectField field in type.fields) { | 422 for (TypeObjectField field in type.fields) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 } | 908 } |
904 return false; | 909 return false; |
905 } | 910 } |
906 | 911 |
907 /** | 912 /** |
908 * Emit the toRequest() code for a class, if appropriate. Returns true if | 913 * Emit the toRequest() code for a class, if appropriate. Returns true if |
909 * code was emitted. | 914 * code was emitted. |
910 */ | 915 */ |
911 bool emitToRequestMember(ImpliedType impliedType) { | 916 bool emitToRequestMember(ImpliedType impliedType) { |
912 if (impliedType.kind == 'requestParams') { | 917 if (impliedType.kind == 'requestParams') { |
| 918 writeln('@override'); |
913 writeln('Request toRequest(String id) {'); | 919 writeln('Request toRequest(String id) {'); |
914 indent(() { | 920 indent(() { |
915 String methodString = | 921 String methodString = |
916 literalString((impliedType.apiNode as Request).longMethod); | 922 literalString((impliedType.apiNode as Request).longMethod); |
917 String jsonPart = impliedType.type != null ? 'toJson()' : 'null'; | 923 String jsonPart = impliedType.type != null ? 'toJson()' : 'null'; |
918 writeln('return new Request(id, $methodString, $jsonPart);'); | 924 writeln('return new Request(id, $methodString, $jsonPart);'); |
919 }); | 925 }); |
920 writeln('}'); | 926 writeln('}'); |
921 return true; | 927 return true; |
922 } | 928 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 | 1273 |
1268 @override | 1274 @override |
1269 String get asClosure => '($type value) => ${callback('value')}'; | 1275 String get asClosure => '($type value) => ${callback('value')}'; |
1270 | 1276 |
1271 @override | 1277 @override |
1272 bool get isIdentity => false; | 1278 bool get isIdentity => false; |
1273 | 1279 |
1274 @override | 1280 @override |
1275 String asSnippet(String value) => callback(value); | 1281 String asSnippet(String value) => callback(value); |
1276 } | 1282 } |
OLD | NEW |