| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /** | 5 /** |
| 6 * Code generation for the file "integration_test_methods.dart". | 6 * Code generation for the file "integration_test_methods.dart". |
| 7 */ | 7 */ |
| 8 library codegenInttestMethods; | 8 library codegenInttestMethods; |
| 9 | 9 |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 if (optionalArgs.isNotEmpty) { | 147 if (optionalArgs.isNotEmpty) { |
| 148 args.add('{${optionalArgs.join(', ')}}'); | 148 args.add('{${optionalArgs.join(', ')}}'); |
| 149 } | 149 } |
| 150 writeln(); | 150 writeln(); |
| 151 docComment(toHtmlVisitor.collectHtml(() { | 151 docComment(toHtmlVisitor.collectHtml(() { |
| 152 toHtmlVisitor.translateHtml(request.html); | 152 toHtmlVisitor.translateHtml(request.html); |
| 153 toHtmlVisitor.describePayload(request.params, 'Parameters'); | 153 toHtmlVisitor.describePayload(request.params, 'Parameters'); |
| 154 toHtmlVisitor.describePayload(request.result, 'Returns'); | 154 toHtmlVisitor.describePayload(request.result, 'Returns'); |
| 155 })); | 155 })); |
| 156 writeln('Future $methodName(${args.join(', ')}) {'); | 156 String resultClass; |
| 157 String futureClass; |
| 158 if (request.result == null) { |
| 159 futureClass = 'Future'; |
| 160 } else { |
| 161 resultClass = |
| 162 camelJoin([request.domainName, request.method, 'result'], doCapitalize
: true); |
| 163 futureClass = 'Future<$resultClass>'; |
| 164 } |
| 165 writeln('$futureClass $methodName(${args.join(', ')}) {'); |
| 157 indent(() { | 166 indent(() { |
| 158 String requestClass = | 167 String requestClass = |
| 159 camelJoin([request.domainName, request.method, 'params'], doCapitalize
: true); | 168 camelJoin([request.domainName, request.method, 'params'], doCapitalize
: true); |
| 160 String resultValidator = | |
| 161 camelJoin(['is', request.domainName, request.method, 'result']); | |
| 162 String paramsVar = 'null'; | 169 String paramsVar = 'null'; |
| 163 if (request.params != null) { | 170 if (request.params != null) { |
| 164 paramsVar = 'params'; | 171 paramsVar = 'params'; |
| 165 List<String> args = <String>[]; | 172 List<String> args = <String>[]; |
| 166 List<String> optionalArgs = <String>[]; | 173 List<String> optionalArgs = <String>[]; |
| 167 for (TypeObjectField field in request.params.fields) { | 174 for (TypeObjectField field in request.params.fields) { |
| 168 if (field.optional) { | 175 if (field.optional) { |
| 169 optionalArgs.add('${field.name}: ${field.name}'); | 176 optionalArgs.add('${field.name}: ${field.name}'); |
| 170 } else { | 177 } else { |
| 171 args.add(field.name); | 178 args.add(field.name); |
| 172 } | 179 } |
| 173 } | 180 } |
| 174 args.addAll(optionalArgs); | 181 args.addAll(optionalArgs); |
| 175 writeln('var params = new $requestClass(${args.join(', ')}).toJson();'); | 182 writeln('var params = new $requestClass(${args.join(', ')}).toJson();'); |
| 176 } | 183 } |
| 177 writeln( | 184 writeln( |
| 178 'return server.send(${JSON.encode(request.longMethod)}, $paramsVar)'); | 185 'return server.send(${JSON.encode(request.longMethod)}, $paramsVar)'); |
| 179 indent(() { | 186 indent(() { |
| 180 writeln(' .then((result) {'); | 187 writeln(' .then((result) {'); |
| 181 writeln('expect(result, $resultValidator);'); | 188 if (request.result != null) { |
| 182 writeln('return result;'); | 189 String kind = 'null'; |
| 190 if (requestClass == 'EditGetRefactoringParams') { |
| 191 kind = 'kind'; |
| 192 } |
| 193 writeln('ResponseDecoder decoder = new ResponseDecoder($kind);'); |
| 194 writeln( |
| 195 "return new $resultClass.fromJson(decoder, 'result', result);"); |
| 196 } else { |
| 197 writeln('expect(result, isNull);'); |
| 198 writeln('return null;'); |
| 199 } |
| 183 }); | 200 }); |
| 184 writeln('});'); | 201 writeln('});'); |
| 185 }); | 202 }); |
| 186 writeln('}'); | 203 writeln('}'); |
| 187 } | 204 } |
| 188 | 205 |
| 189 /** | 206 /** |
| 190 * Generate a function argument for the given parameter field. | 207 * Generate a function argument for the given parameter field. |
| 191 */ | 208 */ |
| 192 String formatArgument(TypeObjectField field) => | 209 String formatArgument(TypeObjectField field) => |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 new CodegenInttestMethodsVisitor(readApi()); | 249 new CodegenInttestMethodsVisitor(readApi()); |
| 233 return visitor.collectCode(visitor.visitApi); | 250 return visitor.collectCode(visitor.visitApi); |
| 234 }); | 251 }); |
| 235 | 252 |
| 236 /** | 253 /** |
| 237 * Translate spec_input.html into protocol_matchers.dart. | 254 * Translate spec_input.html into protocol_matchers.dart. |
| 238 */ | 255 */ |
| 239 main() { | 256 main() { |
| 240 target.generate(); | 257 target.generate(); |
| 241 } | 258 } |
| OLD | NEW |