Skip to content

Commit dbcf447

Browse files
author
Kostiantyn Sologubov
committed
fixes per review comments
1 parent ca852ea commit dbcf447

File tree

10 files changed

+73
-63
lines changed

10 files changed

+73
-63
lines changed

third_party.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Introduction
22

3-
This file is broken into three Parts: SDL Base, SDL Android, and SDL Java. SDL Android and SDL Java are sub projects of SDL Base. Additionally, SDL Java contains two sub-projects: SDL JavaSE and SDL JavaEE.
3+
This file is broken into four Parts: SDL Base, SDL Android, SDL Java and Utils/Generator. SDL Android and SDL Java are sub projects of SDL Base. Additionally, SDL Java contains two sub-projects: SDL JavaSE and SDL JavaEE. Utils/Generator is Proxy Library RPC Generator for SDL BASE.
44

55
## SDL BASE
66

@@ -86,4 +86,43 @@ The third party software included and used by this project is:
8686
SDL JavaEE inherits any license defined in SDL JavaSE.
8787

8888

89+
## Utils
90+
91+
### Generator
92+
93+
Proxy Library RPC Generator inherits any license defined in SDL BASE.
94+
95+
#### Third Party Licenses
96+
97+
Both the source and binary distributions of this software contain
98+
some third party software. All the third party software included
99+
or linked is redistributed under the terms and conditions of their
100+
original licenses.
101+
102+
The third party software included and used by this project is:
103+
104+
**xmlschema**
105+
106+
* Licensed under MIT License
107+
* See [https://pypi.org/project/xmlschema/](https://pypi.org/project/xmlschema/)
108+
109+
**Jinja2**
110+
111+
* Licensed under BSD License (BSD-3-Clause)
112+
* See [https://pypi.org/project/Jinja2/](https://pypi.org/project/Jinja2/)
113+
114+
**coverage**
115+
116+
* Licensed under Apache Software License (Apache 2.0)
117+
* See [https://pypi.org/project/coverage/](https://pypi.org/project/coverage/)
118+
119+
**pathlib2**
120+
121+
* Licensed under MIT License
122+
* See [https://pypi.org/project/pathlib2/](https://pypi.org/project/pathlib2/)
123+
124+
**pylint**
125+
126+
* Licensed under GNU General Public License (GPL)
127+
* See [https://pypi.org/project/pylint/](https://pypi.org/project/pylint/)
89128

utils/generator/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ def write_file(self, file_name, template, data):
280280
"""
281281
Calling producer/transformer instance to transform initial Model to dict used in jinja2 templates.
282282
Applying transformed dict to jinja2 templates and writing to appropriate file
283-
:param file_name: output js file
283+
:param file_name: output java file
284284
:param template: name of template
285-
:param data: transformed moder ready for apply to Jinja2 template
285+
:param data: transformed model ready for apply to Jinja2 template
286286
"""
287287
file_name.parents[0].mkdir(parents=True, exist_ok=True)
288288
try:

utils/generator/templates/enum_template.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public enum {{class_name}} {
2424
{%- endif %}
2525
{%- if kind == "simple" %}
2626
{{param.name}}{{ "," if not loop.last }}
27+
{%- elif kind == "complex" %}
28+
{{param.name}}({{param.value}}){{ "," if not loop.last }}
2729
{%- elif kind == "custom" %}
2830
{{param.name}}({{param.internal}}){{ "," if not loop.last }}
2931
{%- endif %}
@@ -44,11 +46,14 @@ public enum {{class_name}} {
4446
return null;
4547
}
4648
}
47-
{%- elif kind == "custom" %}
49+
{%- elif kind == "complex" or kind == "custom" %}
4850
{%- if return_type == "String" %}
4951

5052
private final String INTERNAL_NAME;
5153

54+
/**
55+
* Private constructor
56+
*/
5257
private {{class_name}}(String internalName) {
5358
this.INTERNAL_NAME = internalName;
5459
}
@@ -72,20 +77,32 @@ public enum {{class_name}} {
7277
return null;
7378
}
7479

80+
/**
81+
* Return String value of element
82+
*
83+
* @return String
84+
*/
7585
@Override
7686
public String toString() {
7787
return INTERNAL_NAME;
7888
}
7989
{%- elif return_type == "int" %}
8090

8191
private final int VALUE;
92+
8293
/**
8394
* Private constructor
8495
*/
8596
private {{class_name}} (int value) {
8697
this.VALUE = value;
8798
}
8899

100+
/**
101+
* Convert int to {{class_name}}
102+
*
103+
* @param value int
104+
* @return {{class_name}}
105+
*/
89106
public static {{class_name}} valueForInt(int value) {
90107
for ({{class_name}} anEnum : EnumSet.allOf({{class_name}}.class)) {
91108
if (anEnum.getValue() == value) {
@@ -95,28 +112,14 @@ public String toString() {
95112
return null;
96113
}
97114

115+
/**
116+
* Return value of element
117+
*
118+
* @return int
119+
*/
98120
public int getValue(){
99121
return VALUE;
100122
}
101-
{%- elif return_type == "bool" %}
102-
103-
boolean IS_QUERYABLE;
104-
105-
{{class_name}}(boolean isQueryable) {
106-
this.IS_QUERYABLE = isQueryable;
107-
}
108-
109-
public boolean isQueryable() {
110-
return IS_QUERYABLE;
111-
}
112-
113-
public static {{class_name}} valueForString(String value) {
114-
try {
115-
return valueOf(value);
116-
} catch (Exception e) {
117-
return null;
118-
}
119-
}
120123
{%- endif %}
121124
{%- endif %}
122125
}

utils/generator/templates/function_template.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Constructs a new {{class_name}} object
1313
*
1414
* @param success whether the request is successfully processed
15-
* @param resultCode whether the request is successfully processed
15+
* @param resultCode result code of processed request
1616
*/
1717
public {{class_name}}(@NonNull Boolean success, @NonNull Result resultCode) {
1818
this();
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{%- if p.param_doc is not defined %}
21
{%- if p.description is defined %}
32
{%- for d in p.description %}
43
{%- if loop.index == 1 -%}
@@ -9,15 +8,6 @@
98
{%- else %}
109
* @return {{p.last}}
1110
{%- endif -%}
12-
{%- else -%}
13-
{%- set l = p.last|length + 8 -%}
14-
* {% for v in p.param_doc -%}
15-
{%- if loop.index == 1 -%}
16-
@return {{p.last}} {{v}}
17-
{%- else -%}
18-
* {{v|indent(l,True)}}
19-
{%- endif -%}{% endfor -%}
20-
{%- endif -%}
2111
{%- if p.since is defined %}
2212
* @since SmartDeviceLink {{p.since}}
2313
{%- endif %}
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{%- if p.param_doc is not defined %}
21
{%- if p.description is defined %}
32
{%- for d in p.description %}
43
{%- if loop.index == 1 -%}
@@ -9,15 +8,6 @@
98
{%- else %}
109
* @param {{p.last}}
1110
{%- endif -%}
12-
{%- else -%}
13-
{%- set l = p.last|length + 8 -%}
14-
* {% for v in p.param_doc -%}
15-
{%- if loop.index == 1 -%}
16-
@param {{p.last}} {{v}}
17-
{%- else -%}
18-
* {{v|indent(l,True)}}
19-
{%- endif -%}{% endfor -%}
20-
{%- endif -%}
2111
{%- if p.since is defined %}
2212
* @since SmartDeviceLink {{p.since}}
2313
{%- endif %}

utils/generator/transformers/common_producer.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ class InterfaceProducerCommon(ABC):
2020
version = '1.0.0'
2121

2222
def __init__(self, container_name, enums_package, structs_package, package_name,
23-
enum_names=(), struct_names=(), mapping=None, all_mapping=None):
24-
if all_mapping is None:
25-
all_mapping = OrderedDict()
23+
enum_names=(), struct_names=()):
2624
self.logger = logging.getLogger('Generator.InterfaceProducerCommon')
2725
self.container_name = container_name
2826
self.enum_names = enum_names
2927
self.struct_names = struct_names
3028
self.enums_package = enums_package
3129
self.structs_package = structs_package
32-
self.mapping = mapping
33-
self.all_mapping = all_mapping
3430
self.package_name = package_name
3531
self._params = namedtuple('params', 'deprecated description key last mandatory origin return_type since title '
3632
'param_doc name')
@@ -99,10 +95,6 @@ def extract_type(self, param):
9995
def evaluate(t1):
10096
if isinstance(t1, Struct) or isinstance(t1, Enum):
10197
name = t1.name
102-
element_type = 'enums' if isinstance(t1, Enum) else 'structs'
103-
if element_type in self.all_mapping and name in self.all_mapping[element_type] \
104-
and 'rename' in self.all_mapping[element_type][name]:
105-
name = self.all_mapping[element_type][name]['rename']
10698
return name
10799
else:
108100
return type(t1).__name__

utils/generator/transformers/enums_producer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def transform(self, item: Enum) -> dict:
3838

3939
for param in getattr(item, self.container_name).values():
4040
(t, p) = self.extract_param(param, item.name)
41-
if t == 'custom':
41+
if t == 'complex':
42+
kind = t
43+
elif t == 'custom' and kind != 'complex':
4244
kind = t
4345
return_type = self.extract_type(param)
4446

@@ -74,7 +76,7 @@ def extract_param(self, param: EnumElement, item_name):
7476
d['name'] = self.key(n)
7577
d['value'] = param.value
7678
d['internal'] = '"{}"'.format(n)
77-
kind = 'custom'
79+
kind = 'complex'
7880
elif getattr(param, 'internal_name', None) is not None:
7981
if param.internal_name.startswith(item_name):
8082
n = param.internal_name[len(item_name):]
@@ -100,9 +102,7 @@ def extract_param(self, param: EnumElement, item_name):
100102
@staticmethod
101103
def extract_imports(param):
102104
imports = []
103-
if getattr(param, 'value', None):
104-
imports.extend(['java.util.EnumSet', 'java.util.HashMap', 'java.util.Iterator', 'java.util.Map.Entry'])
105-
elif getattr(param, 'internal_name', None):
105+
if getattr(param, 'value', None) or getattr(param, 'internal_name', None):
106106
imports.append('java.util.EnumSet')
107107
return imports
108108

@@ -113,7 +113,7 @@ def extract_type(self, param: EnumElement) -> str:
113113
:param param: sub-element (EnumElement) of element from initial Model
114114
:return: string with sub-element type
115115
"""
116-
if getattr(param, 'hex_value') is not None or getattr(param, 'value') is not None:
116+
if getattr(param, 'value') is not None:
117117
return 'int'
118118
else:
119119
return 'String'

utils/generator/transformers/functions_producer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def transform(self, item: Function) -> dict:
8181
description = self.extract_description(item.description)
8282
if description:
8383
render['description'] = description
84-
if imports:
85-
render['imports'] = imports
8684
if params:
8785
render['params'] = params
8886

utils/generator/transformers/structs_producer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ def transform(self, item: Struct) -> dict:
6060
description = self.extract_description(item.description)
6161
if description:
6262
render['description'] = description
63-
if imports:
64-
render['imports'] = imports
6563
if params:
6664
render['params'] = params
6765

0 commit comments

Comments
 (0)