Support inverted go const and var objects

Changes class creation to a generator and invert list of const/var names to
multiple objects.
go-parsed-example
Anthony Johnson 9 years ago
parent 181c7ea2a4
commit f0772d1a57

@ -129,8 +129,8 @@ class AutoAPIDomain(object):
for path in self.find_files(pattern):
data = self.read_file(path, format=format)
if data:
obj = self.create_class(data)
if obj is not None:
for obj in self.create_class(data):
print obj
self.add_object(obj)
def create_class(self, obj):

@ -37,35 +37,34 @@ class DotNetDomain(AutoAPIDomain):
:param data: dictionary data from Roslyn output artifact
'''
# TODO replace this with a global mapping
self.list_classes = [
DotNetNamespace, DotNetClass, DotNetEnum,
DotNetStruct, DotNetInterface, DotNetDelegate
]
self.detail_classes = [
DotNetProperty, DotNetMethod, DotNetConstructor,
DotNetField, DotNetEvent
]
classes = self.detail_classes + self.list_classes
obj = None
for cls in classes:
if data.get('type', '').lower() == cls.type.lower():
obj = cls(data)
break
if data.get('id', None) in MADE:
print "DOING IT AGAIN: %s" % data.get('id')
MADE.add(data['id'])
# Append child objects
# TODO this should recurse in the case we're getting back more complex
# argument listings
# if 'children' in data:
# for item in data['children']:
# child_obj = self.create_class(item)
# obj.children.append(child_obj)
return obj
obj_map = dict(
(cls.type, cls) for cls
in [
DotNetNamespace, DotNetClass, DotNetEnum, DotNetStruct,
DotNetInterface, DotNetDelegate, DotNetProperty, DotNetMethod,
DotNetConstructor, DotNetField, DotNetEvent
])
try:
cls = obj_map[data['type']]
except KeyError:
self.app.warn('Unknown type: %s', data)
else:
obj = cls(data)
# TODO what is MADE?
if data.get('id', None) in MADE:
self.app.warn("Object already added: %s" % data.get('id'))
MADE.add(data['id'])
# Append child objects
# TODO this should recurse in the case we're getting back more
# complex argument listings
# if 'children' in data:
# for item in data['children']:
# child_obj = self.create_class(item)
# obj.children.append(child_obj)
yield obj
def get_objects(self, pattern):
'''Trigger find of serialized sources and build objects'''

@ -49,25 +49,32 @@ class GoDomain(AutoAPIDomain):
:param data: dictionary data from godocjson output
'''
# TODO replace this with a global mapping
classes = [GoConstant, GoFunction, GoPackage, GoVariable, GoType, GoMethod]
obj = None
_type = data.get('type', None)
if _type is None or not _type:
self.app.warn('Missing type: %s' % data)
for cls in classes:
if _type == cls.type.lower():
obj = cls(data)
if obj is None:
obj_map = dict(
(cls.type, cls) for cls
in [GoConstant, GoFunction, GoPackage, GoVariable, GoType, GoMethod]
)
try:
cls = obj_map[data['type']]
except KeyError as e:
self.app.warn('Unknown Type: %s' % data)
return obj
for child_type in ['consts', 'types', 'vars', 'funcs']:
for child_data in data.get(child_type, []):
child_obj = self.create_class(child_data)
if child_obj is not None:
obj.children.append(child_obj)
return obj
else:
if cls.inverted_names and 'names' in data:
# Handle types that have reversed names parameter
for name in data['names']:
data_inv = {}
data_inv.update(data)
data_inv['name'] = name
if 'names' in data_inv:
del data_inv['names']
for obj in self.create_class(data_inv):
yield obj
else:
# Recurse for children
obj = cls(data)
for child_type in ['consts', 'types', 'vars', 'funcs']:
for child_data in data.get(child_type, []):
obj.children += list(self.create_class(child_data))
yield obj
def full(self):
self.get_objects(self.get_config('autoapi_file_pattern'), format='json')
@ -107,11 +114,12 @@ class GoDomain(AutoAPIDomain):
class GoBase(AutoAPIBase):
language = 'go'
inverted_names = False
def __init__(self, obj):
super(GoBase, self).__init__(obj)
self.name = obj.get('name') or obj.get('packageName')
self.id = obj.get('packageImportPath') or self.name
self.id = self.name
# Second level
self.imports = obj.get('imports', [])
@ -164,6 +172,7 @@ class GoBase(AutoAPIBase):
class GoVariable(GoBase):
type = 'var'
inverted_names = True
class GoMethod(GoBase):
@ -173,6 +182,7 @@ class GoMethod(GoBase):
class GoConstant(GoBase):
type = 'const'
inverted_names = True
class GoFunction(GoBase):

@ -30,25 +30,21 @@ class PythonDomain(AutoAPIDomain):
Recurse into :py:meth:`create_class` to create child object
instances
:param data: dictionary data from Roslyn output artifact
:param data: dictionary data of epydoc output
'''
# TODO replace this with a global mapping
classes = [PythonClass, PythonFunction, PythonModule]
obj = None
for cls in classes:
if data['type'].lower() == cls.type.lower():
obj = cls(data)
if not obj:
print "Unknown Type: %s" % data['type']
# Append child objects
# TODO this should recurse in the case we're getting back more complex
# argument listings
if 'children' in data:
for item in data['children']:
child_obj = self.create_class(item)
obj.children.append(child_obj)
return obj
obj_map = dict((cls.type, cls) for cls
in [PythonClass, PythonFunction, PythonModule])
try:
cls = obj_map[data['type']]
except KeyError:
self.app.warn("Unknown Type: %s" % data['type'])
else:
obj = cls(data)
if 'children' in data:
for child_data in data['children']:
child_obj = self.create_class(child_data)
obj.children.append(child_obj)
yield obj
def read_file(self, path):
'''Read file input into memory, returning deserialized objects

Loading…
Cancel
Save