API: Use string type instead of u8.
[vpp.git] / extras / japi / java / jvpp / gen / jvppgen / types_gen.py
1 #!/usr/bin/env python2
2 #
3 # Copyright (c) 2016,2018 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from string import Template
16
17 from jvpp_common_gen import generate_hash_code, generate_equals, generate_to_string, generate_fields
18 from jvpp_model import Class
19
20
21 def generate_types(work_dir, model, logger):
22     logger.debug("Generating custom types for %s " % model.json_api_files)
23
24     for t in model.types:
25         if not isinstance(t, Class):
26             continue
27         logger.debug("Generating DTO for type %s", t)
28         type_class_name = t.java_name
29         fields = t.fields
30         type_class = _TYPE_TEMPLATE.substitute(
31             plugin_package=model.plugin_package,
32             c_type_name=t.name,
33             json_filename=model.json_api_files,
34             json_definition=t.doc,
35             java_type_name=type_class_name,
36             fields=generate_fields(fields),
37             hash_code=generate_hash_code(fields),
38             equals=generate_equals(type_class_name, fields),
39             to_string=generate_to_string(type_class_name, fields)
40         )
41         with open("%s/%s.java" % (work_dir, type_class_name), "w") as f:
42             f.write(type_class)
43
44 _TYPE_TEMPLATE = Template("""
45 package $plugin_package.types;
46
47 /**
48  * <p>This class represents $c_type_name type definition.
49  * <br>It was generated by jvpp_types_gen.py based on $json_filename:
50  * <pre>
51 $json_definition
52  * </pre>
53  */
54 public final class $java_type_name {
55 $fields
56 $hash_code
57 $equals
58 $to_string
59 }
60 """)