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

Side by Side Diff: mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl

Issue 607933002: mojo: Fix java generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs and emptu package. 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
OLDNEW
1 {% from "constant_definition.tmpl" import constant_def %} 1 {% from "constant_definition.tmpl" import constant_def %}
2 {% from "enum_definition.tmpl" import enum_def %} 2 {% from "enum_definition.tmpl" import enum_def %}
3 {% from "struct_definition.tmpl" import struct_def %} 3 {% from "struct_definition.tmpl" import struct_def %}
4 4
5 {%- macro declare_params(parameters, boxed=false) %} 5 {%- macro declare_params(parameters, boxed=false) %}
6 {%- for param in parameters -%} 6 {%- for param in parameters -%}
7 {{param.kind|java_type(boxed)}} {{param|name}} 7 {{param.kind|java_type(boxed)}} {{param|name}}
8 {%- if not loop.last %}, {% endif %} 8 {%- if not loop.last %}, {% endif %}
9 {%- endfor %} 9 {%- endfor %}
10 {%- endmacro %} 10 {%- endmacro %}
11 11
12 {% macro declare_request_params(method) %} 12 {% macro declare_request_params(method) %}
13 {{declare_params(method.parameters)}} 13 {{declare_params(method.parameters)}}
14 {%- if method.response_parameters != None -%} 14 {%- if method.response_parameters != None -%}
15 {%- if method.parameters %}, {% endif %} 15 {%- if method.parameters %}, {% endif %}
16 {{method|interface_response_name}} callback 16 {{method|interface_response_name}} callback
17 {%- endif -%} 17 {%- endif -%}
18 {% endmacro %} 18 {% endmacro %}
19 19
20 {%- macro declare_callback(method) -%} 20 {%- macro declare_callback(method) -%}
21 21
22 interface {{method|interface_response_name}} extends org.chromium.mojo.bindings. Callbacks.Callback{{method.response_parameters|length}}< 22 interface {{method|interface_response_name}} extends org.chromium.mojo.bindings. Callbacks.Callback{{method.response_parameters|length}}{% if method.response_par ameters %}<
23 {%- for param in method.response_parameters -%} 23 {%- for param in method.response_parameters -%}
24 {{param.kind|java_type(True)}} 24 {{param.kind|java_type(True)}}
25 {%- if not loop.last %}, {% endif %} 25 {%- if not loop.last %}, {% endif %}
26 {%- endfor -%} 26 {%- endfor -%}
27 > { } 27 >{% endif %} { }
28 {%- endmacro -%} 28 {%- endmacro -%}
29 29
30 {%- macro run_callback(variable, parameters) -%} 30 {%- macro run_callback(variable, parameters) -%}
31 {%- if parameters -%} 31 {%- if parameters -%}
32 {%- for param in parameters -%} 32 {%- for param in parameters -%}
33 {{variable}}.{{param|name}} 33 {{variable}}.{{param|name}}
34 {%- if not loop.last %}, {% endif %} 34 {%- if not loop.last %}, {% endif %}
35 {%- endfor -%} 35 {%- endfor -%}
36 {%- endif -%} 36 {%- endif -%}
37 {%- endmacro -%} 37 {%- endmacro -%}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 (interface|has_method_without_response and not with_response) %} 98 (interface|has_method_without_response and not with_response) %}
99 try { 99 try {
100 org.chromium.mojo.bindings.ServiceMessage messageWithHeader = 100 org.chromium.mojo.bindings.ServiceMessage messageWithHeader =
101 message.asServiceMessage(); 101 message.asServiceMessage();
102 org.chromium.mojo.bindings.MessageHeader header = messageWithHeader.getHeade r(); 102 org.chromium.mojo.bindings.MessageHeader header = messageWithHeader.getHeade r();
103 if (!header.validateHeader({{flags(with_response, True)}})) { 103 if (!header.validateHeader({{flags(with_response, True)}})) {
104 return false; 104 return false;
105 } 105 }
106 switch(header.getType()) { 106 switch(header.getType()) {
107 {% for method in interface.methods %} 107 {% for method in interface.methods %}
108 {% if (with_response and method.response_parameters) or 108 {% if (with_response and method.response_parameters != None) or
109 (not with_response and not method.response_parameters) %} 109 (not with_response and method.response_parameters == None) %}
110 {% set request_struct = method|struct_from_method %} 110 {% set request_struct = method|struct_from_method %}
111 {% if with_response %} 111 {% if with_response %}
112 {% set response_struct = method|response_struct_from_method %} 112 {% set response_struct = method|response_struct_from_method %}
113 {% endif %} 113 {% endif %}
114 case {{method|method_ordinal_name}}: { 114 case {{method|method_ordinal_name}}: {
115 {% if method.parameters %} 115 {% if method.parameters %}
116 {{request_struct|name}} data = 116 {{request_struct|name}} data =
117 {{request_struct|name}}.deserialize(messageWithHeader.getPay load()); 117 {{request_struct|name}}.deserialize(messageWithHeader.getPay load());
118 {% else %} 118 {% else %}
119 {{request_struct|name}}.deserialize(messageWithHeader.getPayload()); 119 {{request_struct|name}}.deserialize(messageWithHeader.getPayload());
(...skipping 25 matching lines...) Expand all
145 {{enum_def(enum, false)|indent(4)}} 145 {{enum_def(enum, false)|indent(4)}}
146 {% endfor %} 146 {% endfor %}
147 147
148 public interface Proxy extends {{interface|name}}, {{super_class(client, Fal se)}}.Proxy{% if client %}<{{client|java_type}}>{% endif %} { 148 public interface Proxy extends {{interface|name}}, {{super_class(client, Fal se)}}.Proxy{% if client %}<{{client|java_type}}>{% endif %} {
149 } 149 }
150 150
151 {{manager_class(interface, client)}} MANAGER = {{interface|name}}_Internal.M ANAGER; 151 {{manager_class(interface, client)}} MANAGER = {{interface|name}}_Internal.M ANAGER;
152 {% for method in interface.methods %} 152 {% for method in interface.methods %}
153 153
154 void {{method|name}}({{declare_request_params(method)}}); 154 void {{method|name}}({{declare_request_params(method)}});
155 {% if method.response_parameters %} 155 {% if method.response_parameters != None %}
156 {{declare_callback(method)|indent(4)}} 156 {{declare_callback(method)|indent(4)}}
157 {% endif %} 157 {% endif %}
158 {% endfor %} 158 {% endfor %}
159 } 159 }
160 {% endmacro %} 160 {% endmacro %}
161 161
162 {% macro interface_internal_def(interface, client) %} 162 {% macro interface_internal_def(interface, client) %}
163 class {{interface|name}}_Internal { 163 class {{interface|name}}_Internal {
164 164
165 {{manager_def(interface, client)|indent(4)}} 165 {{manager_def(interface, client)|indent(4)}}
166 166
167 {% for method in interface.methods %} 167 {% for method in interface.methods %}
168 private static final int {{method|method_ordinal_name}} = {{method.ordinal}} ; 168 private static final int {{method|method_ordinal_name}} = {{method.ordinal}} ;
169 {% endfor %} 169 {% endfor %}
170 170
171 static final class Proxy extends {% if client %}org.chromium.mojo.bindings.I nterfaceWithClient.AbstractProxy<{{client|java_type}}>{% else %}org.chromium.moj o.bindings.Interface.AbstractProxy{% endif %} implements {{interface|name}}.Prox y { 171 static final class Proxy extends {% if client %}org.chromium.mojo.bindings.I nterfaceWithClient.AbstractProxy<{{client|java_type}}>{% else %}org.chromium.moj o.bindings.Interface.AbstractProxy{% endif %} implements {{interface|name}}.Prox y {
172 172
173 Proxy(org.chromium.mojo.system.Core core, 173 Proxy(org.chromium.mojo.system.Core core,
174 org.chromium.mojo.bindings.MessageReceiverWithResponder messageRec eiver) { 174 org.chromium.mojo.bindings.MessageReceiverWithResponder messageRec eiver) {
175 super(core, messageReceiver); 175 super(core, messageReceiver);
176 } 176 }
177 {% for method in interface.methods %} 177 {% for method in interface.methods %}
178 178
179 @Override 179 @Override
180 public void {{method|name}}({{declare_request_params(method)}}) { 180 public void {{method|name}}({{declare_request_params(method)}}) {
181 {% set request_struct = method|struct_from_method %} 181 {% set request_struct = method|struct_from_method %}
182 {{request_struct|name}} message = new {{request_struct|name}}(); 182 {{request_struct|name}} _message = new {{request_struct|name}}();
183 {% for param in method.parameters %} 183 {% for param in method.parameters %}
184 message.{{param|name}} = {{param|name}}; 184 _message.{{param|name}} = {{param|name}};
185 {% endfor %} 185 {% endfor %}
186 {% if method.response_parameters %} 186 {% if method.response_parameters != None %}
187 getMessageReceiver().acceptWithResponder( 187 getMessageReceiver().acceptWithResponder(
188 message.serializeWithHeader( 188 _message.serializeWithHeader(
189 getCore(), 189 getCore(),
190 new org.chromium.mojo.bindings.MessageHeader( 190 new org.chromium.mojo.bindings.MessageHeader(
191 {{method|method_ordinal_name}}, 191 {{method|method_ordinal_name}},
192 {{flags_for_method(method, True)}}, 192 {{flags_for_method(method, True)}},
193 0)), 193 0)),
194 new {{method|response_struct_from_method|name}}ForwardToCall back(callback)); 194 new {{method|response_struct_from_method|name}}ForwardToCall back(callback));
195 {% else %} 195 {% else %}
196 getMessageReceiver().accept( 196 getMessageReceiver().accept(
197 message.serializeWithHeader( 197 _message.serializeWithHeader(
198 getCore(), 198 getCore(),
199 new org.chromium.mojo.bindings.MessageHeader({{metho d|method_ordinal_name}}))); 199 new org.chromium.mojo.bindings.MessageHeader({{metho d|method_ordinal_name}})));
200 {% endif %} 200 {% endif %}
201 } 201 }
202 {% endfor %} 202 {% endfor %}
203 203
204 } 204 }
205 205
206 static final class Stub extends org.chromium.mojo.bindings.Interface.Stub<{{ interface|name}}> { 206 static final class Stub extends org.chromium.mojo.bindings.Interface.Stub<{{ interface|name}}> {
207 207
208 Stub(org.chromium.mojo.system.Core core, {{interface|name}} impl) { 208 Stub(org.chromium.mojo.system.Core core, {{interface|name}} impl) {
209 super(core, impl); 209 super(core, impl);
210 } 210 }
211 211
212 @Override 212 @Override
213 public boolean accept(org.chromium.mojo.bindings.Message message) { 213 public boolean accept(org.chromium.mojo.bindings.Message message) {
214 {{accept_body(interface, False)|indent(12)}} 214 {{accept_body(interface, False)|indent(12)}}
215 } 215 }
216 216
217 @Override 217 @Override
218 public boolean acceptWithResponder(org.chromium.mojo.bindings.Message me ssage, org.chromium.mojo.bindings.MessageReceiver receiver) { 218 public boolean acceptWithResponder(org.chromium.mojo.bindings.Message me ssage, org.chromium.mojo.bindings.MessageReceiver receiver) {
219 {{accept_body(interface, True)|indent(12)}} 219 {{accept_body(interface, True)|indent(12)}}
220 } 220 }
221 } 221 }
222 {% for method in interface.methods %} 222 {% for method in interface.methods %}
223 223
224 {{ struct_def(method|struct_from_method, True)|indent(4) }} 224 {{ struct_def(method|struct_from_method, True)|indent(4) }}
225 {% if method.response_parameters %} 225 {% if method.response_parameters != None %}
226 {% set response_struct = method|response_struct_from_method %} 226 {% set response_struct = method|response_struct_from_method %}
227 227
228 {{ struct_def(response_struct, True)|indent(4) }} 228 {{ struct_def(response_struct, True)|indent(4) }}
229 229
230 static class {{response_struct|name}}ForwardToCallback extends org.chromium. mojo.bindings.SideEffectFreeCloseable 230 static class {{response_struct|name}}ForwardToCallback extends org.chromium. mojo.bindings.SideEffectFreeCloseable
231 implements org.chromium.mojo.bindings.MessageReceiver { 231 implements org.chromium.mojo.bindings.MessageReceiver {
232 private final {{interface|name}}.{{method|interface_response_name}} mCal lback; 232 private final {{interface|name}}.{{method|interface_response_name}} mCal lback;
233 233
234 {{response_struct|name}}ForwardToCallback({{interface|name}}.{{method|in terface_response_name}} callback) { 234 {{response_struct|name}}ForwardToCallback({{interface|name}}.{{method|in terface_response_name}} callback) {
235 this.mCallback = callback; 235 this.mCallback = callback;
236 } 236 }
237 237
238 @Override 238 @Override
239 public boolean accept(org.chromium.mojo.bindings.Message message) { 239 public boolean accept(org.chromium.mojo.bindings.Message message) {
240 try { 240 try {
241 org.chromium.mojo.bindings.ServiceMessage messageWithHeader = 241 org.chromium.mojo.bindings.ServiceMessage messageWithHeader =
242 message.asServiceMessage(); 242 message.asServiceMessage();
243 org.chromium.mojo.bindings.MessageHeader header = messageWithHea der.getHeader(); 243 org.chromium.mojo.bindings.MessageHeader header = messageWithHea der.getHeader();
244 if (!header.validateHeader({{method|method_ordinal_name}}, 244 if (!header.validateHeader({{method|method_ordinal_name}},
245 {{flags_for_method(method, False)}})) { 245 {{flags_for_method(method, False)}})) {
246 return false; 246 return false;
247 } 247 }
248 {% if method.response_parameters|length %}
248 {{response_struct|name}} response = {{response_struct|name}}.des erialize(messageWithHeader.getPayload()); 249 {{response_struct|name}} response = {{response_struct|name}}.des erialize(messageWithHeader.getPayload());
250 {% endif %}
249 mCallback.call({{run_callback('response', method.response_parame ters)}}); 251 mCallback.call({{run_callback('response', method.response_parame ters)}});
250 return true; 252 return true;
251 } catch (org.chromium.mojo.bindings.DeserializationException e) { 253 } catch (org.chromium.mojo.bindings.DeserializationException e) {
252 return false; 254 return false;
253 } 255 }
254 } 256 }
255 } 257 }
256 258
257 static class {{response_struct|name}}ProxyToResponder implements {{interface |name}}.{{method|interface_response_name}} { 259 static class {{response_struct|name}}ProxyToResponder implements {{interface |name}}.{{method|interface_response_name}} {
258 260
259 private final org.chromium.mojo.system.Core mCore; 261 private final org.chromium.mojo.system.Core mCore;
260 private final org.chromium.mojo.bindings.MessageReceiver mMessageReceive r; 262 private final org.chromium.mojo.bindings.MessageReceiver mMessageReceive r;
261 private final long mRequestId; 263 private final long mRequestId;
262 264
263 {{response_struct|name}}ProxyToResponder( 265 {{response_struct|name}}ProxyToResponder(
264 org.chromium.mojo.system.Core core, 266 org.chromium.mojo.system.Core core,
265 org.chromium.mojo.bindings.MessageReceiver messageReceiver, 267 org.chromium.mojo.bindings.MessageReceiver messageReceiver,
266 long requestId) { 268 long requestId) {
267 mCore = core; 269 mCore = core;
268 mMessageReceiver = messageReceiver; 270 mMessageReceiver = messageReceiver;
269 mRequestId = requestId; 271 mRequestId = requestId;
270 } 272 }
271 273
272 @Override 274 @Override
273 public void call({{declare_params(method.response_parameters, true)}}) { 275 public void call({{declare_params(method.response_parameters, true)}}) {
274 {{response_struct|name}} response = new {{response_struct|name}}(); 276 {{response_struct|name}} _response = new {{response_struct|name}}();
275 {% for param in method.response_parameters %} 277 {% for param in method.response_parameters %}
276 response.{{param|name}} = {{param|name}}; 278 _response.{{param|name}} = {{param|name}};
277 {% endfor %} 279 {% endfor %}
278 org.chromium.mojo.bindings.ServiceMessage message = 280 org.chromium.mojo.bindings.ServiceMessage _message =
279 response.serializeWithHeader( 281 _response.serializeWithHeader(
280 mCore, 282 mCore,
281 new org.chromium.mojo.bindings.MessageHeader( 283 new org.chromium.mojo.bindings.MessageHeader(
282 {{method|method_ordinal_name}}, 284 {{method|method_ordinal_name}},
283 {{flags_for_method(method, False)}}, 285 {{flags_for_method(method, False)}},
284 mRequestId)); 286 mRequestId));
285 mMessageReceiver.accept(message); 287 mMessageReceiver.accept(_message);
286 } 288 }
287 } 289 }
288 {% endif %} 290 {% endif %}
289 {% endfor %} 291 {% endfor %}
290 292
291 } 293 }
292 {% endmacro %} 294 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698