Commit 08837c74 authored by François Grisez's avatar François Grisez

Fix methods summary links

parent 8c28e1a1
...@@ -187,8 +187,7 @@ class SphinxPage(object): ...@@ -187,8 +187,7 @@ class SphinxPage(object):
def _make_selector(self, obj): def _make_selector(self, obj):
links = [] links = []
ref = metadoc.Reference(None) ref = metadoc.Reference.make_ref_from_object(None, obj)
ref.relatedObject = obj
for lang in self.langs: for lang in self.langs:
if lang is self.lang: if lang is self.lang:
link = lang.displayName link = lang.displayName
......
...@@ -138,12 +138,25 @@ class Reference(ParagraphPart): ...@@ -138,12 +138,25 @@ class Reference(ParagraphPart):
ParagraphPart.__init__(self) ParagraphPart.__init__(self)
self.cname = cname self.cname = cname
self.relatedObject = None self.relatedObject = None
def translate(self, docTranslator, **kargs): @staticmethod
return docTranslator.translate_reference(self, **kargs) def make_ref_from_object(cname, obj):
if isinstance(obj, (abstractapi.Enum, abstractapi.Enumerator, abstractapi.Class, abstractapi.Interface)):
ref = ClassReference(cname)
elif isinstance(obj, abstractapi.Method):
ref = FunctionReference(cname)
else:
raise TypeError('cannot create documentation reference from {0}'.format(str(obj)))
ref.relatedObject = obj
return ref
class ClassReference(Reference): class ClassReference(Reference):
def translate(self, docTranslator, **kargs):
if self.relatedObject is None:
raise ReferenceTranslationError(self.cname)
return docTranslator.translate_class_reference(self, **kargs)
def resolve(self, api): def resolve(self, api):
try: try:
self.relatedObject = api.classesIndex[self.cname] self.relatedObject = api.classesIndex[self.cname]
...@@ -152,6 +165,11 @@ class ClassReference(Reference): ...@@ -152,6 +165,11 @@ class ClassReference(Reference):
class FunctionReference(Reference): class FunctionReference(Reference):
def translate(self, docTranslator, **kargs):
if self.relatedObject is None:
raise ReferenceTranslationError(self.cname)
return docTranslator.translate_function_reference(self, **kargs)
def resolve(self, api): def resolve(self, api):
try: try:
self.relatedObject = api.methodsIndex[self.cname] self.relatedObject = api.methodsIndex[self.cname]
...@@ -495,13 +513,16 @@ class DoxygenTranslator(Translator): ...@@ -495,13 +513,16 @@ class DoxygenTranslator(Translator):
def _tag_as_brief(self, lines): def _tag_as_brief(self, lines):
if len(lines) > 0: if len(lines) > 0:
lines[0] = '@brief ' + lines[0] lines[0] = '@brief ' + lines[0]
def translate_reference(self, ref): def translate_class_reference(self, ref, **kargs):
refStr = Translator.translate_reference(self, ref)
if isinstance(ref.relatedObject, (abstractapi.Class, abstractapi.Enum)): if isinstance(ref.relatedObject, (abstractapi.Class, abstractapi.Enum)):
return '#' + refStr return '#' + Translator.translate_reference(self, ref)
elif isinstance(ref.relatedObject, abstractapi.Method): else:
return refStr + '()' raise ReferenceTranslationError(ref.cname)
def translate_function_reference(self, ref, **kargs):
if isinstance(ref.relatedObject, abstractapi.Method):
return Translator.translate_reference(self, ref) + '()'
else: else:
raise ReferenceTranslationError(ref.cname) raise ReferenceTranslationError(ref.cname)
...@@ -588,18 +609,24 @@ class SphinxTranslator(Translator): ...@@ -588,18 +609,24 @@ class SphinxTranslator(Translator):
return self.get_declarator(typeName) return self.get_declarator(typeName)
except AttributeError: except AttributeError:
raise ValueError("'{0}' referencer type not supported".format(typeName)) raise ValueError("'{0}' referencer type not supported".format(typeName))
def translate_reference(self, ref, label=None, namespace=None): def translate_class_reference(self, ref, label=None, namespace=None):
strRef = Translator.translate_reference(self, ref, absName=True) return ':{tag}:`{label} <{ref}>`'.format(
kargs = { tag=self._sphinx_ref_tag(ref),
'tag' : self._sphinx_ref_tag(ref), label=label if label is not None else Translator.translate_reference(self, ref, namespace=namespace),
'ref' : strRef, ref=Translator.translate_reference(self, ref, absName=True)
} )
kargs['label'] = label if label is not None else Translator.translate_reference(self, ref, namespace=namespace)
if isinstance(ref, FunctionReference): def translate_function_reference(self, ref, label=None, namespace=None):
kargs['label'] += '()' paramTypes = []
if self.domain != 'c':
return ':{tag}:`{label} <{ref}>`'.format(**kargs) for arg in ref.relatedObject.args:
paramTypes.append(arg._type.translate(self.langTranslator))
return ':{tag}:`{label} <{ref}>`'.format(
tag=self._sphinx_ref_tag(ref),
label=label if label is not None else '{0}()'.format(Translator.translate_reference(self, ref, namespace=namespace)),
ref='{0}({1})'.format(Translator.translate_reference(self, ref, absName=True), ', '.join(paramTypes))
)
def translate_keyword(self, keyword): def translate_keyword(self, keyword):
translatedKeyword = Translator.translate_keyword(self, keyword) translatedKeyword = Translator.translate_keyword(self, keyword)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment