Skip to content

Commit f906f36

Browse files
author
Qiming Yuan
committed
Fix bug in doc generator.
1 parent 6affc98 commit f906f36

File tree

1 file changed

+51
-43
lines changed

1 file changed

+51
-43
lines changed

generator/csharp.py

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def emit_xml(self, doc, tag, **attrs):
376376
self.emit(tag_start + ' />')
377377
else:
378378
self.emit_wrapped_text('{0}>{1}</{2}>'.format(tag_start, doc, tag),
379-
process=self._tag_handler)
379+
process=self._get_tag_handler(self._ns))
380380

381381
@contextmanager
382382
def xml_block(self, tag, **attrs):
@@ -519,47 +519,50 @@ def emit_ctor_summary(self, class_name):
519519
self.emit_summary('Initializes a new instance of the <see cref="{0}" /> '
520520
'class.'.format(class_name))
521521

522-
def _tag_handler(self, tag, value):
523-
"""
524-
Passed as to the process_doc() method to handle tags that are found in
525-
the documentation string
526-
527-
Args:
528-
tag (Union[str, unicode]): The tag type, one of 'field|link|route|type|val'
529-
value (Union[str, unicode]): The value of the tag.
530-
"""
531-
if tag == 'field':
532-
if '.' in value:
533-
parts = map(self._public_name, value.split('.'))
534-
return '<see cref="{0}.{1}.{2}" />'.format(self._namespace_name, self._ns, '.'.join(parts))
535-
elif self._tag_context:
536-
data_type, is_constructor = self._tag_context
537-
if is_constructor:
522+
def _get_tag_handler(self, ns):
523+
def tag_handler(tag, value):
524+
"""
525+
Passed as to the process_doc() method to handle tags that are found in
526+
the documentation string
527+
528+
Args:
529+
tag (Union[str, unicode]): The tag type, one of 'field|link|route|type|val'
530+
value (Union[str, unicode]): The value of the tag.
531+
"""
532+
if tag == 'field':
533+
if '.' in value:
534+
parts = map(self._public_name, value.split('.'))
535+
return '<see cref="{0}.{1}.{2}" />'.format(self._namespace_name, ns, '.'.join(parts))
536+
elif self._tag_context:
537+
data_type, is_constructor = self._tag_context
538+
if is_constructor:
539+
return '<paramref name="{0}" />'.format(self._arg_name(value, is_doc=True))
540+
else:
541+
return '<see cref="{0}" />'.format(self._public_name(value))
542+
else:
538543
return '<paramref name="{0}" />'.format(self._arg_name(value, is_doc=True))
544+
elif tag == 'link':
545+
parts = value.split(' ')
546+
uri = parts[-1]
547+
text = ' '.join(parts[:-1])
548+
return '<a href="{0}">{1}</a>'.format(uri, text)
549+
elif tag == 'route':
550+
if '.' in value:
551+
ns_name, route_name = map(self._public_name, value.split('.'))
539552
else:
540-
return '<see cref="{0}" />'.format(self._public_name(value))
541-
else:
542-
return '<paramref name="{0}" />'.format(self._arg_name(value, is_doc=True))
543-
elif tag == 'link':
544-
parts = value.split(' ')
545-
uri = parts[-1]
546-
text = ' '.join(parts[:-1])
547-
return '<a href="{0}">{1}</a>'.format(uri, text)
548-
elif tag == 'route':
549-
if '.' in value:
550-
ns_name, route_name = map(self._public_name, value.split('.'))
553+
ns_name, route_name = ns, self._public_name(value)
554+
auth_type = self._route_auth_map[(ns_name, route_name)]
555+
556+
return ('<see cref="{0}.{1}.Routes.{1}{2}Routes.{3}Async" />'.format(
557+
self._namespace_name, ns_name, auth_type, route_name))
558+
elif tag == 'type':
559+
return '<see cref="{0}" />'.format(self._public_name(value))
560+
elif tag == 'val':
561+
return '<c>{0}</c>'.format(value.strip('`'))
551562
else:
552-
ns_name, route_name = self._ns, self._public_name(value)
553-
auth_type = self._route_auth_map[(ns_name, route_name)]
554-
555-
return ('<see cref="{0}.{1}.Routes.{1}{2}Routes.{3}Async" />'.format(
556-
self._namespace_name, ns_name, auth_type, route_name))
557-
elif tag == 'type':
558-
return '<see cref="{0}" />'.format(self._public_name(value))
559-
elif tag == 'val':
560-
return '<c>{0}</c>'.format(value.strip('`'))
561-
else:
562-
assert False, 'Unknown tag: {0}:{1}'.format(tag, value)
563+
assert False, 'Unknown tag: {0}:{1}'.format(tag, value)
564+
565+
return tag_handler
563566

564567
def _typename(self, data_type, void=None, is_property=False, is_response=False, include_namespace=False):
565568
"""
@@ -1238,6 +1241,8 @@ def _make_struct_constructor_args(self, struct):
12381241
arguments are being enumerated.
12391242
"""
12401243
constructor_args = []
1244+
ns_name = self._public_name(struct.namespace.name)
1245+
12411246
for field in struct.all_fields:
12421247
fieldtype = self._typename(field.data_type)
12431248
arg_name = self._arg_name(field.name)
@@ -1256,7 +1261,7 @@ def _make_struct_constructor_args(self, struct):
12561261

12571262
doc = field.doc or 'The {0}'.format(self._name_words(field.name))
12581263
self._tag_context = (struct, True)
1259-
doc = self.process_doc(doc, self._tag_handler)
1264+
doc = self.process_doc(doc, self._get_tag_handler(ns_name))
12601265
self._tag_context = None
12611266
doc = '<param name="{0}">{1}</param>'.format(doc_name, doc)
12621267

@@ -2051,6 +2056,9 @@ def _generate_obsolete_attribute(self, deprecated, prefix='', suffix=''):
20512056
"""
20522057
if not deprecated:
20532058
return
2054-
2055-
self.emit('[sys.Obsolete("This function is deprecated, please use {0}{1}{2} instead.")]'
2056-
.format(prefix, self._public_name(deprecated.by.name), suffix))
2059+
2060+
if not deprecated.by:
2061+
self.emit('[sys.Obsolete("This function is deprecated")]')
2062+
else:
2063+
self.emit('[sys.Obsolete("This function is deprecated, please use {0}{1}{2} instead.")]'
2064+
.format(prefix, self._public_name(deprecated.by.name), suffix))

0 commit comments

Comments
 (0)