Skip to content

Commit

Permalink
Kotlin: Remove double-item naming
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Jul 22, 2024
1 parent 2cdc44f commit c1398a7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions glean_parser/templates/kotlin.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ data class {{ obj.name|Camelize }}{{ suffix }}(
@Serializable
data class {{ name }}(
{% for itemname, val in struct.properties.items() %}
{% if val.type == "object" %}
{% if val.type == "array" %}
var {{itemname|camelize}}: {{ name ~ itemname|Camelize }} = {{ name ~ itemname|Camelize }}(),
{% elif val.type == "object" %}
var {{itemname|camelize}}: {{ name ~ "Item" ~ itemname|Camelize ~ "Object" }}? = null,
{% elif val.type == "array" %}
var {{itemname|camelize}}: {{ name ~ "Item" ~ itemname|Camelize }} = {{ name ~ "Item" ~ itemname|Camelize }}(),
{% else %}
var {{itemname|camelize}}: {{val.type|structure_type_name}}? = null,
{% endif %}
Expand All @@ -123,7 +123,7 @@ data class {{ obj.name|Camelize }}{{ suffix }}(

{% for itemname, val in struct.properties.items() %}
{% if val.type == "array" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize %}
{% set nested_name = name ~ itemname|Camelize %}
{{ generate_structure(nested_name, val) }}
{% elif val.type == "object" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize ~ "Object" %}
Expand All @@ -141,7 +141,7 @@ data class {{ obj.name|Camelize }}{{ suffix }}(
{%- elif struct.type == "object" -%}
{% for itemname, val in struct.properties.items() %}
{% if val.type == "array" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize %}
{% set nested_name = name ~ itemname|Camelize %}
{{ generate_structure_typealias(nested_name, val) }}
{% elif val.type == "object" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize ~ "Object" %}
Expand Down
10 changes: 5 additions & 5 deletions glean_parser/templates/rust.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Jinja2 template is not. Please file bugs! #}
#[serde(deny_unknown_fields)]
pub struct {{ name }} {
{% for itemname, val in struct.properties.items() %}
{% if val.type == "object" %}
{% if val.type == "array" %}
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub {{itemname|snake_case}}: {{ name ~ itemname|Camelize }},
{% elif val.type == "object" %}
#[serde(skip_serializing_if = "Option::is_none")]
pub {{itemname|snake_case}}: Option<{{ name ~ "Item" ~ itemname|Camelize ~ "Object" }}>,
{% elif val.type == "array" %}
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub {{itemname|snake_case}}: {{ name ~ "Item" ~ itemname|Camelize }},
{% else %}
#[serde(skip_serializing_if = "Option::is_none")]
pub {{itemname|snake_case}}: Option<{{val.type|structure_type_name}}>,
Expand All @@ -35,7 +35,7 @@ Jinja2 template is not. Please file bugs! #}

{% for itemname, val in struct.properties.items() %}
{% if val.type == "array" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize %}
{% set nested_name = name ~ itemname|Camelize %}
{{ generate_structure(nested_name, val) }}
{% elif val.type == "object" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize ~ "Object" %}
Expand Down
8 changes: 4 additions & 4 deletions glean_parser/templates/swift.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ struct {{ obj.name|Camelize }}{{ suffix }}: EventExtras {
{%- elif struct.type == "object" -%}
struct {{ name }}: Codable, Equatable, ObjectSerialize {
{% for itemname, val in struct.properties.items() %}
{% if val.type == "object" %}
{% if val.type == "array" %}
var {{itemname|camelize|variable_name}}: {{ name ~ itemname|Camelize }}
{% elif val.type == "object" %}
var {{itemname|camelize|variable_name}}: {{ name ~ "Item" ~ itemname|Camelize ~ "Object" }}?
{% elif val.type == "array" %}
var {{itemname|camelize|variable_name}}: {{ name ~ "Item" ~ itemname|Camelize }}
{% else %}
var {{itemname|camelize|variable_name}}: {{val.type|structure_type_name}}?
{% endif %}
Expand All @@ -72,7 +72,7 @@ struct {{ obj.name|Camelize }}{{ suffix }}: EventExtras {

{% for itemname, val in struct.properties.items() %}
{% if val.type == "array" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize %}
{% set nested_name = name ~ itemname|Camelize %}
{{ generate_structure(nested_name, val) }}
{% elif val.type == "object" %}
{% set nested_name = name ~ "Item" ~ itemname|Camelize ~ "Object" %}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_kotlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ def test_object_metric(tmp_path):
assert "data class ThreadsObject(" in content
assert "data class ThreadsObjectItem(" in content
assert (
"var frames: ThreadsObjectItemItemFrames = ThreadsObjectItemItemFrames"
"var frames: ThreadsObjectItemFrames = ThreadsObjectItemFrames"
in content
)

assert "data class ThreadsObjectItemItemFramesItem(" in content
assert "data class ThreadsObjectItemFramesItem(" in content
assert "var moduleIndex: Int? = null," in content
assert "var ip: String? = null," in content
assert "var trust: String? = null," in content
8 changes: 4 additions & 4 deletions tests/test_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ def test_object_metric(tmp_path):

assert "ObjectMetric<ThreadsObject>" in content
assert "pub struct ThreadsObjectItem { " in content
assert "frames: ThreadsObjectItemItemFrames, }" in content
assert "frames: ThreadsObjectItemFrames, }" in content
assert (
"pub type ThreadsObjectItemItemFrames = "
"Vec<ThreadsObjectItemItemFramesItem>;" in content
"pub type ThreadsObjectItemFrames = "
"Vec<ThreadsObjectItemFramesItem>;" in content
)

assert "pub struct ThreadsObjectItemItemFramesItem { " in content
assert "pub struct ThreadsObjectItemFramesItem { " in content
assert "module_index: Option<i64>, " in content
assert "ip: Option<String>, " in content
assert "trust: Option<String>, " in content
Expand Down
4 changes: 2 additions & 2 deletions tests/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ def test_object_metric(tmp_path):
assert "typealias ThreadsObject = [ThreadsObjectItem]" in content
assert "struct ThreadsObjectItem: Codable, Equatable, ObjectSerialize {" in content
assert (
"var frames: ThreadsObjectItemItemFrames"
"var frames: ThreadsObjectItemFrames"
in content
)

assert "struct ThreadsObjectItemItemFramesItem: Codable, Equatable, ObjectSerialize {" in content
assert "struct ThreadsObjectItemFramesItem: Codable, Equatable, ObjectSerialize {" in content
assert "var moduleIndex: Int64?" in content
assert "var ip: String?" in content
assert "var trust: String?" in content

0 comments on commit c1398a7

Please sign in to comment.