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

Unified Diff: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart

Issue 537733002: Use typed RefactoringOptions in the Dart version of the protocol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update also Java generator 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
index e8bccf0bdea0606b0846e2ad3ab10a08ce58dcf3..0d742a483be2c7daccbd97da3575763660b3765d 100644
--- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
+++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
@@ -291,7 +291,11 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
toHtmlVisitor.showType(null, impliedType.type);
}
}));
- writeln('class $className implements HasToJson {');
+ write('class $className');
+ if (impliedType.kind == 'refactoringOptions') {
+ write(' extends RefactoringOptions');
+ }
+ writeln(' implements HasToJson {');
indent(() {
if (emitSpecialStaticMembers(className)) {
writeln();
@@ -964,6 +968,16 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
ImpliedType impliedType) {
String humanReadableNameString =
literalString(impliedType.humanReadableName);
+ if (className == 'RefactoringOptions') {
+ writeln('factory RefactoringOptions.fromJson(JsonDecoder jsonDecoder, '
+ 'String jsonPath, Object json, RefactoringKind kind) {');
+ indent(() {
+ writeln('return _refactoringOptionsFromJson(jsonDecoder, jsonPath, '
+ 'json, kind);');
+ });
+ writeln('}');
+ return;
+ }
writeln(
'factory $className.fromJson(JsonDecoder jsonDecoder, String jsonPath, Object json) {');
indent(() {
@@ -1000,9 +1014,9 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
writeln('$fieldDartType ${field.name};');
writeln('if (json.containsKey($fieldNameString)) {');
indent(() {
- String toJson =
+ String fromJson =
fromJsonCode(fieldType).asSnippet(jsonPath, fieldAccessor);
- writeln('${field.name} = $toJson;');
+ writeln('${field.name} = $fromJson;');
});
write('}');
if (!field.optional) {
@@ -1074,8 +1088,14 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
TypeDecl referencedType = referencedDefinition.type;
if (referencedType is TypeObject || referencedType is TypeEnum) {
return new FromJsonSnippet(
- (String jsonPath, String json) =>
- 'new ${dartType(type)}.fromJson(jsonDecoder, $jsonPath, $json)');
+ (String jsonPath, String json) {
+ String typeName = dartType(type);
+ if (typeName == 'RefactoringOptions') {
+ return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json, kind)';
+ } else {
+ return 'new $typeName.fromJson(jsonDecoder, $jsonPath, $json)';
+ }
+ });
} else {
return fromJsonCode(referencedType);
}

Powered by Google App Engine
This is Rietveld 408576698