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

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

Issue 631553002: Change integration test notifications to use structured objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
« no previous file with comments | « pkg/analysis_server/test/integration/server/status_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 }); 76 });
77 writeln('}'); 77 writeln('}');
78 writeln(); 78 writeln();
79 docComment(toHtmlVisitor.collectHtml(() { 79 docComment(toHtmlVisitor.collectHtml(() {
80 toHtmlVisitor.writeln('Dispatch the notification named [event], and'); 80 toHtmlVisitor.writeln('Dispatch the notification named [event], and');
81 toHtmlVisitor.writeln('containing parameters [params], to the'); 81 toHtmlVisitor.writeln('containing parameters [params], to the');
82 toHtmlVisitor.writeln('appropriate stream.'); 82 toHtmlVisitor.writeln('appropriate stream.');
83 })); 83 }));
84 writeln('void dispatchNotification(String event, params) {'); 84 writeln('void dispatchNotification(String event, params) {');
85 indent(() { 85 indent(() {
86 writeln('ResponseDecoder decoder = new ResponseDecoder(null);');
86 writeln('switch (event) {'); 87 writeln('switch (event) {');
87 indent(() { 88 indent(() {
88 write(notificationSwitchContents.join()); 89 write(notificationSwitchContents.join());
89 writeln('default:'); 90 writeln('default:');
90 indent(() { 91 indent(() {
91 writeln("fail('Unexpected notification: \$event');"); 92 writeln("fail('Unexpected notification: \$event');");
92 writeln('break;'); 93 writeln('break;');
93 }); 94 });
94 }); 95 });
95 writeln('}'); 96 writeln('}');
96 }); 97 });
97 writeln('}'); 98 writeln('}');
98 }); 99 });
99 writeln('}'); 100 writeln('}');
100 } 101 }
101 102
102 @override 103 @override
103 visitNotification(Notification notification) { 104 visitNotification(Notification notification) {
104 String streamName = 105 String streamName =
105 camelJoin(['on', notification.domainName, notification.event]); 106 camelJoin(['on', notification.domainName, notification.event]);
107 String className = camelJoin([notification.domainName, notification.event, ' params'], doCapitalize: true);
106 writeln(); 108 writeln();
107 docComment(toHtmlVisitor.collectHtml(() { 109 docComment(toHtmlVisitor.collectHtml(() {
108 toHtmlVisitor.translateHtml(notification.html); 110 toHtmlVisitor.translateHtml(notification.html);
109 toHtmlVisitor.describePayload(notification.params, 'Parameters'); 111 toHtmlVisitor.describePayload(notification.params, 'Parameters');
110 })); 112 }));
111 writeln('Stream $streamName;'); 113 writeln('Stream<$className> $streamName;');
112 writeln(); 114 writeln();
113 docComment(toHtmlVisitor.collectHtml(() { 115 docComment(toHtmlVisitor.collectHtml(() {
114 toHtmlVisitor.write('Stream controller for [$streamName].'); 116 toHtmlVisitor.write('Stream controller for [$streamName].');
115 })); 117 }));
116 writeln('StreamController _$streamName;'); 118 writeln('StreamController<$className> _$streamName;');
117 fieldInitializationCode.add(collectCode(() { 119 fieldInitializationCode.add(collectCode(() {
118 writeln('_$streamName = new StreamController(sync: true);'); 120 writeln('_$streamName = new StreamController<$className>(sync: true);');
119 writeln('$streamName = _$streamName.stream.asBroadcastStream();'); 121 writeln('$streamName = _$streamName.stream.asBroadcastStream();');
120 })); 122 }));
121 notificationSwitchContents.add(collectCode(() { 123 notificationSwitchContents.add(collectCode(() {
122 writeln('case ${JSON.encode(notification.longEvent)}:'); 124 writeln('case ${JSON.encode(notification.longEvent)}:');
123 indent(() { 125 indent(() {
124 String paramsValidator = 126 String paramsValidator =
125 camelJoin(['is', notification.domainName, notification.event, 'param s']); 127 camelJoin(['is', notification.domainName, notification.event, 'param s']);
126 writeln('expect(params, $paramsValidator);'); 128 writeln('expect(params, $paramsValidator);');
127 writeln('_$streamName.add(params);'); 129 String constructorCall;
130 if (notification.params == null) {
131 constructorCall = 'new $className()';
132 } else {
133 constructorCall = "new $className.fromJson(decoder, 'params', params)" ;
134 }
135 writeln('_$streamName.add($constructorCall);');
128 writeln('break;'); 136 writeln('break;');
129 }); 137 });
130 })); 138 }));
131 } 139 }
132 140
133 @override 141 @override
134 visitRequest(Request request) { 142 visitRequest(Request request) {
135 String methodName = camelJoin(['send', request.domainName, request.method]); 143 String methodName = camelJoin(['send', request.domainName, request.method]);
136 List<String> args = <String>[]; 144 List<String> args = <String>[];
137 List<String> optionalArgs = <String>[]; 145 List<String> optionalArgs = <String>[];
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 new CodegenInttestMethodsVisitor(readApi()); 257 new CodegenInttestMethodsVisitor(readApi());
250 return visitor.collectCode(visitor.visitApi); 258 return visitor.collectCode(visitor.visitApi);
251 }); 259 });
252 260
253 /** 261 /**
254 * Translate spec_input.html into protocol_matchers.dart. 262 * Translate spec_input.html into protocol_matchers.dart.
255 */ 263 */
256 main() { 264 main() {
257 target.generate(); 265 target.generate();
258 } 266 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/integration/server/status_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698