Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: tools/json_schema_compiler/model.py

Issue 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/model.py
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 1b353ac74a0589aa39ac546f9851c9c84b793e1b..df931671e1f8d9b318749a42aa12de8c16cceb96 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -42,6 +42,7 @@ class Namespace(object):
- |source_file_filename| the filename component of |source_file|
- |types| a map of type names to their model.Type
- |functions| a map of function names to their model.Function
+ - |events| a map of event names to their model.Function
- |properties| a map of property names to their model.Property
"""
def __init__(self, json, source_file):
@@ -52,6 +53,7 @@ class Namespace(object):
self.parent = None
_AddTypes(self, json)
_AddFunctions(self, json)
+ _AddEvents(self, json)
_AddProperties(self, json)
class Type(object):
@@ -109,7 +111,7 @@ class Callback(object):
- |params| the parameters to this callback.
"""
def __init__(self, parent, json):
- params = json['parameters']
+ params = json.get('parameters', [])
self.parent = parent
self.params = []
if len(params) == 0:
@@ -134,7 +136,7 @@ class Function(object):
- |callback| the callback parameter to the function. There should be exactly
one
"""
- def __init__(self, parent, json):
+ def __init__(self, parent, json, from_json=False, from_client=False):
self.name = json['name']
self.params = []
self.description = json.get('description')
@@ -148,7 +150,7 @@ class Function(object):
self.callback = Callback(self, param)
else:
self.params.append(Property(self, param['name'], param,
- from_json=True))
+ from_json=from_json, from_client=from_client))
class Property(object):
"""A property of a type OR a parameter to a function.
@@ -165,18 +167,15 @@ class Property(object):
- |item_type| a model.Property representing the type of each element in an
ARRAY
- |properties| the properties of an OBJECT parameter
+ - |from_client| indicates that instances of the Type can originate from the
+ users of generated code, such as top-level types and function results
+ - |from_json| indicates that instances of the Type can originate from the
+ JSON (as described by the schema), such as top-level types and function
+ parameters
"""
def __init__(self, parent, name, json, is_additional_properties=False,
from_json=False, from_client=False):
- """
- Parameters:
- - |from_json| indicates that instances of the Type can originate from the
- JSON (as described by the schema), such as top-level types and function
- parameters
- - |from_client| indicates that instances of the Type can originate from the
- users of generated code, such as top-level types and function results
- """
self.name = name
self._unix_name = UnixName(self.name)
self._unix_name_used = False
@@ -184,6 +183,8 @@ class Property(object):
self.has_value = False
self.description = json.get('description')
self.parent = parent
+ self.from_json = from_json
+ self.from_client = from_client
_AddProperties(self, json)
if is_additional_properties:
self.type_ = PropertyType.ADDITIONAL_PROPERTIES
@@ -215,8 +216,6 @@ class Property(object):
elif json_type == 'object':
self.type_ = PropertyType.OBJECT
# These members are read when this OBJECT Property is used as a Type
- self.from_json = from_json
- self.from_client = from_client
type_ = Type(self, self.name, json)
# self.properties will already have some value from |_AddProperties|.
self.properties.update(type_.properties)
@@ -339,13 +338,22 @@ def _AddTypes(model, json):
model.types[type_.name] = type_
def _AddFunctions(model, json):
- """Adds Function objects to |model| contained in the 'types' field of |json|.
+ """Adds Function objects to |model| contained in the 'functions' field of
+ |json|.
"""
model.functions = {}
for function_json in json.get('functions', []):
- function = Function(model, function_json)
+ function = Function(model, function_json, from_json=True)
model.functions[function.name] = function
+def _AddEvents(model, json):
+ """Adds Function objects to |model| contained in the 'events' field of |json|.
+ """
+ model.events = {}
+ for event_json in json.get('events', []):
+ event = Function(model, event_json, from_client=True)
not at google - send to devlin 2012/07/03 14:21:39 Casual observation that might actually change a wh
Matt Tytel 2012/07/11 02:08:50 Went with removing the Callback object from the ch
+ model.events[event.name] = event
+
def _AddProperties(model, json, from_json=False, from_client=False):
"""Adds model.Property objects to |model| contained in the 'properties' field
of |json|.

Powered by Google App Engine
This is Rietveld 408576698