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

Side by Side Diff: mojo/tools/generate_java_callback_interfaces.py

Issue 310783004: Adding generic callback interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Misc fixes. Created 6 years, 6 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
(Empty)
1 """Generate the org.chromium.mojo.bindings.Callbacks interface"""
2
3 import argparse
4 import sys
5
6 CALLBACK_TEMPLATE = ("""
7 /**
8 * A generic %d argument(s) callback.
9 *
10 * %s
11 */
12 interface Callback%d<%s> {
13 /**
14 * Call the callback.
15 */
16 public void call(%s);
17 }
18 """)
19
20 INTERFACE_TEMPLATE = (
21 """// Copyright 2014 The Chromium Authors. All rights reserved.
22 // Use of this source code is governed by a BSD-style license that can be
23 // found in the LICENSE file.
24
25 // This file has been generated using
26 // mojo/tools/generate_java_callback_interfaces.py
27
28 package org.chromium.mojo.bindings;
29
30 /**
31 * Contain generic interface for callbacks.
32 */
33 public interface Callbacks {
34 %s
35
rmcilroy 2014/06/05 12:10:26 nit - remove this newline to avoid a double newlin
qsr 2014/06/05 12:40:13 Done.
36 }
37 """)
38
39 def GenerateCallback(nb_args):
40 params = '\n * '.join(
41 ['@param <T%d> the type of the %d argument.' % (i+1, i+1)
rmcilroy 2014/06/05 12:10:26 "the type of argument %d."
qsr 2014/06/05 12:40:13 Done.
42 for i in xrange(nb_args)])
43 template_parameters = ', '.join(['T%d' % (i+1) for i in xrange(nb_args)])
44 callback_parameters = ', '.join(['T%d t%d' % ((i+1), (i+1))
45 for i in xrange(nb_args)])
46 return CALLBACK_TEMPLATE % (nb_args, params, nb_args, template_parameters,
47 callback_parameters)
48
49 def main():
50 parser = argparse.ArgumentParser(
51 description="Generate org.chromium.mojo.bindings.Callbacks")
52 parser.add_argument("max_args", nargs=1, type=int,
53 help="maximal number of arguments to generate callbacks for")
54 args = parser.parse_args()
55 max_args = args.max_args[0]
56 print INTERFACE_TEMPLATE % ''.join([GenerateCallback(i+1)
57 for i in xrange(max_args)])
58 return 0
59
60 if __name__ == "__main__":
61 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698