Skip to content

Commit

Permalink
[JsonGen] Fix BluetoothControl name cases (#121) (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm authored Sep 11, 2024
1 parent ee02862 commit 3c71144
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
9 changes: 4 additions & 5 deletions JsonGenerator/source/header_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,16 @@ def ConvertType(var):
enum_spec = { "enum": [e.meta.text if e.meta.text else e.name for e in cppType.items] }
else:
enum_spec = { "enum": [e.meta.text if e.meta.text else e.name.replace("_"," ").title().replace(" ","") for e in cppType.items] }

enum_spec["ids"] = [e.name for e in cppType.items]
enum_spec["hint"] = var.type.Type().name

if not cppType.items[0].auto_value:
enum_spec["values"] = [e.value for e in cppType.items]

for e in cppType.items:
if "endmarker" in e.meta.decorators:
enum_spec["endmarker"] = e.name
break;

if not cppType.items[0].auto_value:
enum_spec["values"] = [e.value for e in cppType.items]

if "bitmask" in var.meta.decorators or "bitmask" in var.type.Type().meta.decorators:
enum_spec["bitmask"] = True
enum_spec["type"] = "string"
Expand Down
29 changes: 23 additions & 6 deletions JsonGenerator/source/json_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ def actual_name(self):
@property
def cpp_name(self): # C++ name of the object
if self.new_name:
return (self.new_name[0].upper() + self.new_name[1:])
_name = self.new_name
elif self.original_name:
return (self.original_name[0].upper() + self.original_name[1:])
_name = self.original_name
else:
return (self.name[0].upper() + self.name[1:])
_name = self.name

return (_name[0].upper() + _name[1:])

@property
def cpp_type(self): # C++ type of the object (e.g. may be array)
Expand Down Expand Up @@ -448,7 +450,7 @@ def __DetermineClassName(self):
classname = self.original_type
elif "class" in self.schema:
# Override class name if "class" property present
classname = self.schema["class"].capitalize
classname = self.schema["class"].capitalize()
elif "hint" in self.schema:
# Override class name if "hint" property present
classname = self.schema["hint"]
Expand Down Expand Up @@ -554,7 +556,7 @@ def cpp_name(self):
if self.is_renamed:
return super().cpp_name
elif isinstance(self.parent, JsonMethod):
return self.parent.cpp_name + super().cpp_name
return self.parent.actual_name.capitalize() + super().cpp_name
elif isinstance(self.parent, JsonArray):
return self.parent.cpp_name
else:
Expand Down Expand Up @@ -765,8 +767,23 @@ def result(self):
def function_name(self):
if "hint" in self.schema:
return self.schema["hint"]
elif self.original_name:
return self.original_name
else:
return self.actual_name[0].upper() + self.actual_name[1:]

@property
def cpp_name(self): # C++ name of the object
if self.new_name:
_name = self.new_name
elif self.original_name:
_name = self.original_name
elif "hint" in self.schema:
_name = self.schema["hint"]
else:
return self.actual_name
_name = self.name

return (_name[0].upper() + _name[1:])

def Headline(self):
return "'%s'%s%s" % (self.json_name, (" - " + self.summary.split(".", 1)[0]) if self.summary else "",
Expand Down

0 comments on commit 3c71144

Please sign in to comment.