OLD | NEW |
(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 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 was generated using |
| 26 // mojo/tools/generate_java_callback_interfaces.py |
| 27 |
| 28 package org.chromium.mojo.bindings; |
| 29 |
| 30 /** |
| 31 * Contains a generic interface for callbacks. |
| 32 */ |
| 33 public interface Callbacks { |
| 34 %s |
| 35 } |
| 36 """) |
| 37 |
| 38 def GenerateCallback(nb_args): |
| 39 params = '\n * '.join( |
| 40 ['@param <T%d> the type of argument %d.' % (i+1, i+1) |
| 41 for i in xrange(nb_args)]) |
| 42 template_parameters = ', '.join(['T%d' % (i+1) for i in xrange(nb_args)]) |
| 43 callback_parameters = ', '.join(['T%d arg%d' % ((i+1), (i+1)) |
| 44 for i in xrange(nb_args)]) |
| 45 return CALLBACK_TEMPLATE % (nb_args, params, nb_args, template_parameters, |
| 46 callback_parameters) |
| 47 |
| 48 def main(): |
| 49 parser = argparse.ArgumentParser( |
| 50 description="Generate org.chromium.mojo.bindings.Callbacks") |
| 51 parser.add_argument("max_args", nargs=1, type=int, |
| 52 help="maximal number of arguments to generate callbacks for") |
| 53 args = parser.parse_args() |
| 54 max_args = args.max_args[0] |
| 55 print INTERFACE_TEMPLATE % ''.join([GenerateCallback(i+1) |
| 56 for i in xrange(max_args)]) |
| 57 return 0 |
| 58 |
| 59 if __name__ == "__main__": |
| 60 sys.exit(main()) |
OLD | NEW |