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

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

Issue 483393002: Analysis server code generation improvements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « pkg/analysis_server/lib/src/protocol2.dart ('k') | pkg/analysis_server/tool/spec/implied_types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a1ef9f83f04ef3eeea776ffb91c6bd53ded896a0..cf0388cfe1a5c777fa80feab6b69c88f40fb18b1 100644
--- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
+++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
@@ -230,7 +230,7 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
toHtmlVisitor.showType(null, impliedType.type);
}
}));
- writeln('class $className {');
+ writeln('class $className implements HasToJson {');
indent(() {
for (TypeObjectField field in type.fields) {
if (field.value != null) {
@@ -251,6 +251,9 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
emitToJsonMember(type);
writeln();
+ if (emitToRequestMember(impliedType)) {
+ writeln();
+ }
writeln('@override');
writeln('String toString() => JSON.encode(toJson());');
writeln();
@@ -315,6 +318,24 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
/**
+ * Emit the toRequest() code for a class, if appropriate. Returns true if
+ * code was emitted.
+ */
+ bool emitToRequestMember(ImpliedType impliedType) {
+ if (impliedType.kind == 'requestParams') {
+ writeln('Request toRequest(String id) {');
+ indent(() {
+ String methodString = literalString((impliedType.apiNode as
+ Request).longMethod);
+ writeln('return new Request(id, $methodString, toJson());');
+ });
+ writeln('}');
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Emit the operator== code for an object class.
*/
void emitObjectEqualsMember(TypeObject type, String className) {
@@ -440,7 +461,7 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
return new ToJsonIdentity(dartType(type));
} else {
return new ToJsonSnippet(dartType(type), (String value) =>
- '$value.map(${itemCode.asClosure})');
+ '$value.map(${itemCode.asClosure}).toList()');
}
} else if (resolvedType is TypeMap) {
ToJsonCode keyCode;
« no previous file with comments | « pkg/analysis_server/lib/src/protocol2.dart ('k') | pkg/analysis_server/tool/spec/implied_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698