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

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

Issue 463163002: Initial cut at generating the AnalysisServer.java interface. Currently this generates a commented o… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nit 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 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 /** 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 25 matching lines...) Expand all
36 */ 36 */
37 List<String> notificationSwitchContents = <String>[]; 37 List<String> notificationSwitchContents = <String>[];
38 38
39 CodegenInttestMethodsVisitor(Api api) 39 CodegenInttestMethodsVisitor(Api api)
40 : super(api), 40 : super(api),
41 toHtmlVisitor = new ToHtmlVisitor(api); 41 toHtmlVisitor = new ToHtmlVisitor(api);
42 42
43 @override 43 @override
44 visitApi() { 44 visitApi() {
45 outputHeader(); 45 outputHeader();
46 writeln();
46 writeln('/**'); 47 writeln('/**');
47 writeln(' * Convenience methods for running integration tests'); 48 writeln(' * Convenience methods for running integration tests');
48 writeln(' */'); 49 writeln(' */');
49 writeln('library test.integration.methods;'); 50 writeln('library test.integration.methods;');
50 writeln(); 51 writeln();
51 writeln("import 'dart:async';"); 52 writeln("import 'dart:async';");
52 writeln(); 53 writeln();
53 writeln("import 'package:unittest/unittest.dart';"); 54 writeln("import 'package:unittest/unittest.dart';");
54 writeln(); 55 writeln();
55 writeln("import 'integration_tests.dart';"); 56 writeln("import 'integration_tests.dart';");
56 writeln("import 'protocol_matchers.dart';"); 57 writeln("import 'protocol_matchers.dart';");
57 writeln(); 58 writeln();
58 writeln(); 59 writeln();
59 writeln('/**'); 60 writeln('/**');
60 writeln(' * Convenience methods for running integration tests'); 61 writeln(' * Convenience methods for running integration tests');
61 writeln(' */'); 62 writeln(' */');
62 writeln('abstract class IntegrationTestMixin {'); 63 writeln('abstract class IntegrationTestMixin {');
63 indent(() { 64 indent(() {
64 writeln('Server get server;'); 65 writeln('Server get server;');
65 super.visitApi(); 66 super.visitApi();
66 writeln(); 67 writeln();
67 docComment(toHtmlVisitor.collectHtml(() { 68 docComment(toHtmlVisitor.collectHtml(() {
68 toHtmlVisitor.writeln('Initialize the fields in InttestMixin, and'); 69 toHtmlVisitor.writeln('Initialize the fields in InttestMixin, and');
69 toHtmlVisitor.writeln('ensure that notifications will be handled.'); 70 toHtmlVisitor.writeln('ensure that notifications will be handled.');
70 }), false); 71 }));
71 writeln('void initializeInttestMixin() {'); 72 writeln('void initializeInttestMixin() {');
72 indent(() { 73 indent(() {
73 write(fieldInitializationCode.join()); 74 write(fieldInitializationCode.join());
74 }); 75 });
75 writeln('}'); 76 writeln('}');
76 writeln(); 77 writeln();
77 docComment(toHtmlVisitor.collectHtml(() { 78 docComment(toHtmlVisitor.collectHtml(() {
78 toHtmlVisitor.writeln('Dispatch the notification named [event], and'); 79 toHtmlVisitor.writeln('Dispatch the notification named [event], and');
79 toHtmlVisitor.writeln('containing parameters [params], to the'); 80 toHtmlVisitor.writeln('containing parameters [params], to the');
80 toHtmlVisitor.writeln('appropriate stream.'); 81 toHtmlVisitor.writeln('appropriate stream.');
81 }), false); 82 }));
82 writeln('void dispatchNotification(String event, params) {'); 83 writeln('void dispatchNotification(String event, params) {');
83 indent(() { 84 indent(() {
84 writeln('switch (event) {'); 85 writeln('switch (event) {');
85 indent(() { 86 indent(() {
86 write(notificationSwitchContents.join()); 87 write(notificationSwitchContents.join());
87 writeln('default:'); 88 writeln('default:');
88 indent(() { 89 indent(() {
89 writeln("fail('Unexpected notification: \$event');"); 90 writeln("fail('Unexpected notification: \$event');");
90 writeln('break;'); 91 writeln('break;');
91 }); 92 });
92 }); 93 });
93 writeln('}'); 94 writeln('}');
94 }); 95 });
95 writeln('}'); 96 writeln('}');
96 }); 97 });
97 writeln('}'); 98 writeln('}');
98 } 99 }
99 100
100 @override 101 @override
101 visitNotification(Notification notification) { 102 visitNotification(Notification notification) {
102 String streamName = camelJoin(['on', notification.domainName, notification.e vent]); 103 String streamName = camelJoin(['on', notification.domainName, notification.e vent]);
103 writeln(); 104 writeln();
104 docComment(toHtmlVisitor.collectHtml(() { 105 docComment(toHtmlVisitor.collectHtml(() {
105 toHtmlVisitor.translateHtml(notification.html); 106 toHtmlVisitor.translateHtml(notification.html);
106 toHtmlVisitor.describePayload(notification.params, 'Parameters'); 107 toHtmlVisitor.describePayload(notification.params, 'Parameters');
107 }), false); 108 }));
108 writeln('Stream $streamName;'); 109 writeln('Stream $streamName;');
109 writeln(); 110 writeln();
110 docComment(toHtmlVisitor.collectHtml(() { 111 docComment(toHtmlVisitor.collectHtml(() {
111 toHtmlVisitor.write('Stream controller for [$streamName].'); 112 toHtmlVisitor.write('Stream controller for [$streamName].');
112 }), false); 113 }));
113 writeln('StreamController _$streamName;'); 114 writeln('StreamController _$streamName;');
114 fieldInitializationCode.add(collectCode(() { 115 fieldInitializationCode.add(collectCode(() {
115 writeln('_$streamName = new StreamController(sync: true);'); 116 writeln('_$streamName = new StreamController(sync: true);');
116 writeln('$streamName = _$streamName.stream.asBroadcastStream();'); 117 writeln('$streamName = _$streamName.stream.asBroadcastStream();');
117 })); 118 }));
118 notificationSwitchContents.add(collectCode(() { 119 notificationSwitchContents.add(collectCode(() {
119 writeln('case ${JSON.encode(notification.longEvent)}:'); 120 writeln('case ${JSON.encode(notification.longEvent)}:');
120 indent(() { 121 indent(() {
121 String paramsValidator = camelJoin(['is', notification.domainName, 122 String paramsValidator = camelJoin(['is', notification.domainName,
122 notification.event, 'params']); 123 notification.event, 'params']);
(...skipping 18 matching lines...) Expand all
141 } 142 }
142 } 143 }
143 } 144 }
144 optionalArgs.add('bool checkTypes: true'); 145 optionalArgs.add('bool checkTypes: true');
145 args.add('{${optionalArgs.join(', ')}}'); 146 args.add('{${optionalArgs.join(', ')}}');
146 writeln(); 147 writeln();
147 docComment(toHtmlVisitor.collectHtml(() { 148 docComment(toHtmlVisitor.collectHtml(() {
148 toHtmlVisitor.translateHtml(request.html); 149 toHtmlVisitor.translateHtml(request.html);
149 toHtmlVisitor.describePayload(request.params, 'Parameters'); 150 toHtmlVisitor.describePayload(request.params, 'Parameters');
150 toHtmlVisitor.describePayload(request.result, 'Returns'); 151 toHtmlVisitor.describePayload(request.result, 'Returns');
151 }), false); 152 }));
152 writeln('Future $methodName(${args.join(', ')}) {'); 153 writeln('Future $methodName(${args.join(', ')}) {');
153 indent(() { 154 indent(() {
154 String paramsValidator = camelJoin(['is', request.domainName, 155 String paramsValidator = camelJoin(['is', request.domainName,
155 request.method, 'params']); 156 request.method, 'params']);
156 String resultValidator = camelJoin(['is', request.domainName, 157 String resultValidator = camelJoin(['is', request.domainName,
157 request.method, 'result']); 158 request.method, 'result']);
158 String paramsVar = 'null'; 159 String paramsVar = 'null';
159 if (request.params != null) { 160 if (request.params != null) {
160 paramsVar = 'params'; 161 paramsVar = 'params';
161 writeln('Map<String, dynamic> params = {};'); 162 writeln('Map<String, dynamic> params = {};');
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 * Translate spec_input.html into protocol_matchers.dart. 243 * Translate spec_input.html into protocol_matchers.dart.
243 */ 244 */
244 main() { 245 main() {
245 CodegenInttestMethodsVisitor visitor = new CodegenInttestMethodsVisitor( 246 CodegenInttestMethodsVisitor visitor = new CodegenInttestMethodsVisitor(
246 readApi()); 247 readApi());
247 String code = visitor.collectCode(visitor.visitApi); 248 String code = visitor.collectCode(visitor.visitApi);
248 File outputFile = new File( 249 File outputFile = new File(
249 '../../test/integration/integration_test_methods.dart'); 250 '../../test/integration/integration_test_methods.dart');
250 outputFile.writeAsStringSync(code); 251 outputFile.writeAsStringSync(code);
251 } 252 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/tool/spec/codegen_analysis_server.dart ('k') | pkg/analysis_server/tool/spec/codegen_java.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698