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

Side by Side Diff: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart

Issue 541823004: Decode RefactoringFeedback automatically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library codegen.protocol; 5 library codegen.protocol;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'api.dart'; 9 import 'api.dart';
10 import 'codegen_tools.dart'; 10 import 'codegen_tools.dart';
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 ImpliedType impliedType) { 285 ImpliedType impliedType) {
286 docComment(toHtmlVisitor.collectHtml(() { 286 docComment(toHtmlVisitor.collectHtml(() {
287 toHtmlVisitor.p(() { 287 toHtmlVisitor.p(() {
288 toHtmlVisitor.write(impliedType.humanReadableName); 288 toHtmlVisitor.write(impliedType.humanReadableName);
289 }); 289 });
290 if (impliedType.type != null) { 290 if (impliedType.type != null) {
291 toHtmlVisitor.showType(null, impliedType.type); 291 toHtmlVisitor.showType(null, impliedType.type);
292 } 292 }
293 })); 293 }));
294 write('class $className'); 294 write('class $className');
295 if (impliedType.kind == 'refactoringFeedback') {
296 write(' extends RefactoringFeedback');
297 }
295 if (impliedType.kind == 'refactoringOptions') { 298 if (impliedType.kind == 'refactoringOptions') {
296 write(' extends RefactoringOptions'); 299 write(' extends RefactoringOptions');
297 } 300 }
298 writeln(' implements HasToJson {'); 301 writeln(' implements HasToJson {');
299 indent(() { 302 indent(() {
300 if (emitSpecialStaticMembers(className)) { 303 if (emitSpecialStaticMembers(className)) {
301 writeln(); 304 writeln();
302 } 305 }
303 for (TypeObjectField field in type.fields) { 306 for (TypeObjectField field in type.fields) {
304 if (field.value != null) { 307 if (field.value != null) {
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 "Don't know how to compare for equality: $resolvedType"); 964 "Don't know how to compare for equality: $resolvedType");
962 } 965 }
963 966
964 /** 967 /**
965 * Emit the method for decoding an object from JSON. 968 * Emit the method for decoding an object from JSON.
966 */ 969 */
967 void emitObjectFromJsonConstructor(String className, TypeObject type, 970 void emitObjectFromJsonConstructor(String className, TypeObject type,
968 ImpliedType impliedType) { 971 ImpliedType impliedType) {
969 String humanReadableNameString = 972 String humanReadableNameString =
970 literalString(impliedType.humanReadableName); 973 literalString(impliedType.humanReadableName);
974 if (className == 'RefactoringFeedback') {
975 writeln('factory RefactoringFeedback.fromJson(JsonDecoder jsonDecoder, '
976 'String jsonPath, Object json, Map responseJson) {');
977 indent(() {
978 writeln('return _refactoringFeedbackFromJson(jsonDecoder, jsonPath, '
979 'json, responseJson);');
980 });
981 writeln('}');
982 return;
983 }
971 if (className == 'RefactoringOptions') { 984 if (className == 'RefactoringOptions') {
972 writeln('factory RefactoringOptions.fromJson(JsonDecoder jsonDecoder, ' 985 writeln('factory RefactoringOptions.fromJson(JsonDecoder jsonDecoder, '
973 'String jsonPath, Object json, RefactoringKind kind) {'); 986 'String jsonPath, Object json, RefactoringKind kind) {');
974 indent(() { 987 indent(() {
975 writeln('return _refactoringOptionsFromJson(jsonDecoder, jsonPath, ' 988 writeln('return _refactoringOptionsFromJson(jsonDecoder, jsonPath, '
976 'json, kind);'); 989 'json, kind);');
977 }); 990 });
978 writeln('}'); 991 writeln('}');
979 return; 992 return;
980 } 993 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 */ 1096 */
1084 FromJsonCode fromJsonCode(TypeDecl type) { 1097 FromJsonCode fromJsonCode(TypeDecl type) {
1085 if (type is TypeReference) { 1098 if (type is TypeReference) {
1086 TypeDefinition referencedDefinition = api.types[type.typeName]; 1099 TypeDefinition referencedDefinition = api.types[type.typeName];
1087 if (referencedDefinition != null) { 1100 if (referencedDefinition != null) {
1088 TypeDecl referencedType = referencedDefinition.type; 1101 TypeDecl referencedType = referencedDefinition.type;
1089 if (referencedType is TypeObject || referencedType is TypeEnum) { 1102 if (referencedType is TypeObject || referencedType is TypeEnum) {
1090 return new FromJsonSnippet( 1103 return new FromJsonSnippet(
1091 (String jsonPath, String json) { 1104 (String jsonPath, String json) {
1092 String typeName = dartType(type); 1105 String typeName = dartType(type);
1093 if (typeName == 'RefactoringOptions') { 1106 if (typeName == 'RefactoringFeedback') {
1107 return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json, json)';
1108 } else if (typeName == 'RefactoringOptions') {
1094 return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json, kind)'; 1109 return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json, kind)';
1095 } else { 1110 } else {
1096 return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json)' ; 1111 return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json)' ;
1097 } 1112 }
1098 }); 1113 });
1099 } else { 1114 } else {
1100 return fromJsonCode(referencedType); 1115 return fromJsonCode(referencedType);
1101 } 1116 }
1102 } else { 1117 } else {
1103 switch (type.typeName) { 1118 switch (type.typeName) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 inputType = 'Request'; 1211 inputType = 'Request';
1197 inputName = 'request'; 1212 inputName = 'request';
1198 fieldName = '_params'; 1213 fieldName = '_params';
1199 makeDecoder = 'new RequestDecoder(request)'; 1214 makeDecoder = 'new RequestDecoder(request)';
1200 constructorName = 'fromRequest'; 1215 constructorName = 'fromRequest';
1201 break; 1216 break;
1202 case 'requestResult': 1217 case 'requestResult':
1203 inputType = 'Response'; 1218 inputType = 'Response';
1204 inputName = 'response'; 1219 inputName = 'response';
1205 fieldName = '_result'; 1220 fieldName = '_result';
1206 makeDecoder = 'new ResponseDecoder()'; 1221 makeDecoder = 'new ResponseDecoder(response)';
1207 constructorName = 'fromResponse'; 1222 constructorName = 'fromResponse';
1208 break; 1223 break;
1209 case 'notificationParams': 1224 case 'notificationParams':
1210 inputType = 'Notification'; 1225 inputType = 'Notification';
1211 inputName = 'notification'; 1226 inputName = 'notification';
1212 fieldName = '_params'; 1227 fieldName = '_params';
1213 makeDecoder = 'new ResponseDecoder()'; 1228 makeDecoder = 'new ResponseDecoder(null)';
1214 constructorName = 'fromNotification'; 1229 constructorName = 'fromNotification';
1215 break; 1230 break;
1216 case 'refactoringFeedback':
1217 inputType = 'EditGetRefactoringResult';
1218 inputName = 'refactoringResult';
1219 fieldName = 'feedback';
1220 makeDecoder = 'new ResponseDecoder()';
1221 constructorName = 'fromRefactoringResult';
1222 break;
1223 case 'refactoringOptions': 1231 case 'refactoringOptions':
1224 inputType = 'EditGetRefactoringParams'; 1232 inputType = 'EditGetRefactoringParams';
1225 inputName = 'refactoringParams'; 1233 inputName = 'refactoringParams';
1226 fieldName = 'options'; 1234 fieldName = 'options';
1227 makeDecoder = 'new RequestDecoder(request)'; 1235 makeDecoder = 'new RequestDecoder(request)';
1228 constructorName = 'fromRefactoringParams'; 1236 constructorName = 'fromRefactoringParams';
1229 extraArgs.add('Request request'); 1237 extraArgs.add('Request request');
1230 break; 1238 break;
1231 default: 1239 default:
1232 return false; 1240 return false;
1233 } 1241 }
1234 List<String> args = ['$inputType $inputName']; 1242 List<String> args = ['$inputType $inputName'];
1235 args.addAll(extraArgs); 1243 args.addAll(extraArgs);
1236 writeln('factory $className.$constructorName(${args.join(', ')}) {'); 1244 writeln('factory $className.$constructorName(${args.join(', ')}) {');
1237 indent(() { 1245 indent(() {
1238 String fieldNameString = 1246 String fieldNameString =
1239 literalString(fieldName.replaceFirst(new RegExp('^_'), '')); 1247 literalString(fieldName.replaceFirst(new RegExp('^_'), ''));
1240 writeln('return new $className.fromJson('); 1248 if (className == 'EditGetRefactoringParams') {
1241 writeln(' $makeDecoder, $fieldNameString, $inputName.$fieldName);'); 1249 writeln('var params = new $className.fromJson(');
1250 writeln(' $makeDecoder, $fieldNameString, $inputName.$fieldName);');
1251 writeln('REQUEST_ID_REFACTORING_KINDS[request.id] = params.kind;');
1252 writeln('return params;');
1253 } else {
1254 writeln('return new $className.fromJson(');
1255 writeln(' $makeDecoder, $fieldNameString, $inputName.$fieldName);');
1256 }
1242 }); 1257 });
1243 writeln('}'); 1258 writeln('}');
1244 return true; 1259 return true;
1245 } 1260 }
1246 1261
1247 /** 1262 /**
1248 * Create a string literal that evaluates to [s]. 1263 * Create a string literal that evaluates to [s].
1249 */ 1264 */
1250 String literalString(String s) { 1265 String literalString(String s) {
1251 return JSON.encode(s); 1266 return JSON.encode(s);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); 1301 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi());
1287 return visitor.collectCode(visitor.visitApi); 1302 return visitor.collectCode(visitor.visitApi);
1288 }); 1303 });
1289 1304
1290 /** 1305 /**
1291 * Translate spec_input.html into protocol_matchers.dart. 1306 * Translate spec_input.html into protocol_matchers.dart.
1292 */ 1307 */
1293 main() { 1308 main() {
1294 target.generate(); 1309 target.generate();
1295 } 1310 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/protocol_test.dart ('k') | pkg/analysis_server/tool/spec/codegen_java_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698