Commit 7f9636f9 authored by François Grisez's avatar François Grisez

Fix references

parent 08837c74
{{#make_chapter}}{{{className}}} class{{/make_chapter}}
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{namespace}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/hasNamespaceDeclarator}}
{{#isNotJava}}
.. {{#write_declarator}}class{{/write_declarator}}:: {{{fullClassName}}}
{{/isNotJava}}
{{#isJava}}
.. java:package:: {{{namespace}}}
{{#make_chapter}}{{{className}}} class{{/make_chapter}}
.. java:type:: public interface {{{className}}};
{{/isJava}}
.. {{#write_declarator}}class{{/write_declarator}}:: {{{classDeclaration}}}
{{#briefDoc}}
{{#lines}}
......@@ -24,6 +24,14 @@
{{{selector}}}
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{fullClassName}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/hasNamespaceDeclarator}}
Summary
=======
......@@ -63,6 +71,9 @@ Properties
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{fullClassName}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/hasNamespaceDeclarator}}
{{#getter}}
......@@ -110,6 +121,9 @@ Public methods
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{fullClassName}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/hasNamespaceDeclarator}}
{{#methods}}
......@@ -138,6 +152,9 @@ Class methods
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{fullClassName}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/hasNamespaceDeclarator}}
{{#classMethods}}
......
{{#namespace}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{namespace}}}
{{#isJava}}
:noindex:
{{/isJava}}
{{/namespace}}
{{#enums}}
{{{sectionName}}}
.. {{#write_declarator}}enum{{/write_declarator}}:: {{{fullName}}}
{{#isNotJava}}
.. {{#write_declarator}}enum{{/write_declarator}}:: {{{fullName}}}
{{/isNotJava}}
{{#isJava}}
.. java:type:: public enum {{{name}}};
{{/isJava}}
{{#briefDesc}}
{{#lines}}
......@@ -11,10 +23,7 @@
{{{selector}}}
{{#hasNamespaceDeclarator}}
.. {{#write_declarator}}namespace{{/write_declarator}}:: {{{namespace}}}
{{/hasNamespaceDeclarator}}
{{#isNotJava}}
{{#enumerators}}
.. {{#write_declarator}}enumerator{{/write_declarator}}:: {{{name}}}{{#value}} = {{{value}}}{{/value}}
......@@ -27,4 +36,5 @@
{{{selector}}}
{{/enumerators}}
{{/isNotJava}}
{{/enums}}
......@@ -162,6 +162,14 @@ class SphinxPage(object):
@property
def docTranslator(self):
return self.lang.docTranslator
@property
def isJava(self):
return self.lang.langCode == 'Java'
@property
def isNotJava(self):
return not self.isJava
def make_chapter(self):
return lambda text: RstTools.make_chapter(pystache.render(text, self))
......@@ -193,9 +201,7 @@ class SphinxPage(object):
link = lang.displayName
else:
link = ref.translate(lang.docTranslator, label=lang.displayName)
links.append(link)
return ' '.join(links)
@staticmethod
......@@ -213,9 +219,10 @@ class IndexPage(SphinxPage):
class EnumsPage(SphinxPage):
def __init__(self, lang, langs, enums):
def __init__(self, lang, langs, api):
SphinxPage.__init__(self, lang, langs, 'enums.rst')
self._translate_enums(enums)
self.namespace = api.namespace.name.translate(lang.nameTranslator) if lang.langCode != 'C' else None
self._translate_enums(api.namespace.enums)
def _translate_enums(self, enums):
self.enums = []
......@@ -227,7 +234,6 @@ class EnumsPage(SphinxPage):
'enumerators' : self._translate_enum_values(enum),
'selector' : self._make_selector(enum)
}
translatedEnum['namespace'] = self._get_translated_namespace(enum) if self.lang.langCode == 'Cpp' else translatedEnum['fullName']
translatedEnum['sectionName'] = RstTools.make_section(translatedEnum['name'])
self.enums.append(translatedEnum)
......@@ -249,7 +255,8 @@ class ClassPage(SphinxPage):
def __init__(self, _class, lang, langs):
filename = SphinxPage._classname_to_filename(_class.name)
SphinxPage.__init__(self, lang, langs, filename)
self.namespace = self._get_translated_namespace(_class)
namespace = _class.find_first_ancestor_by_type(abstractapi.Namespace)
self.namespace = namespace.name.translate(self.lang.nameTranslator, recursive=True)
self.className = _class.name.translate(self.lang.nameTranslator)
self.fullClassName = _class.name.translate(self.lang.nameTranslator, recursive=True)
self.briefDoc = _class.briefDescription.translate(self.docTranslator)
......@@ -258,6 +265,10 @@ class ClassPage(SphinxPage):
self.methods = self._translate_methods(_class.instanceMethods)
self.classMethods = self._translate_methods(_class.classMethods)
self.selector = self._make_selector(_class)
@property
def classDeclaration(self):
return 'public interface {0}'.format(self.className) if self.lang.langCode == 'Java' else self.className
@property
def hasMethods(self):
......@@ -276,11 +287,12 @@ class ClassPage(SphinxPage):
for property_ in properties:
propertyAttr = {
'name' : property_.name.translate(self.lang.nameTranslator),
'ref_label' : '{0}_{1}'.format(self.lang.langCode, property_.name.to_snake_case(fullName=True)),
'getter' : self._translate_method(property_.getter) if property_.getter is not None else None,
'setter' : self._translate_method(property_.setter) if property_.setter is not None else None
}
propertyAttr['title'] = RstTools.make_subsubsection(propertyAttr['name'])
propertyAttr['ref_label'] = (self.lang.langCode + '_')
propertyAttr['ref_label'] += (property_.getter.name.to_snake_case(fullName=True) if property_.getter is not None else property_.setter.name.to_snake_case(fullName=True))
translatedProperties.append(propertyAttr)
return translatedProperties
......@@ -291,18 +303,16 @@ class ClassPage(SphinxPage):
return translatedMethods
def _translate_method(self, method):
prototypeParams = {}
if self.lang.langCode == 'Cpp':
prototypeParams['showStdNs'] = True
namespace = method.find_first_ancestor_by_type(abstractapi.Class)
methAttr = {
'prototype' : method.translate_as_prototype(self.lang.langTranslator, **prototypeParams),
'prototype' : method.translate_as_prototype(self.lang.langTranslator, namespace=namespace),
'briefDoc' : method.briefDescription.translate(self.docTranslator),
'detailedDoc' : method.detailedDescription.translate(self.docTranslator),
'selector' : self._make_selector(method)
}
reference = metadoc.FunctionReference(None)
reference.relatedObject = method
methAttr['link'] = reference.translate(self.lang.docTranslator)
methAttr['link'] = reference.translate(self.lang.docTranslator, namespace=method.find_first_ancestor_by_type(abstractapi.Class, abstractapi.Interface))
return methAttr
@property
......@@ -331,14 +341,6 @@ class ClassPage(SphinxPage):
table.addrow([method['link'], briefDoc])
return table
@property
def isJava(self):
return self.lang.langCode == 'Java'
@property
def isNotJava(self):
return not self.isJava
class DocGenerator:
def __init__(self, api):
......@@ -357,7 +359,7 @@ class DocGenerator:
if not os.path.exists(directory):
os.mkdir(directory)
enumsPage = EnumsPage(lang, self.languages, self.api.namespace.enums)
enumsPage = EnumsPage(lang, self.languages, self.api)
enumsPage.write(directory)
indexPage = IndexPage(lang, self.languages)
......
This diff is collapsed.
......@@ -435,12 +435,11 @@ class Translator:
else:
if namespace is None:
description = ref.find_root()
namespaceObj = description.relatedObject.find_first_ancestor_by_type(abstractapi.Namespace, abstractapi.Class)
namespace = namespaceObj.name
if namespace.is_prefix_of(ref.relatedObject.name):
commonName = namespace
namespace = description.relatedObject.find_first_ancestor_by_type(abstractapi.Namespace, abstractapi.Class)
if namespace.name.is_prefix_of(ref.relatedObject.name):
commonName = namespace.name
else:
commonName = metaname.Name.find_common_parent(ref.relatedObject.name, namespace)
commonName = metaname.Name.find_common_parent(ref.relatedObject.name, namespace.name)
return ref.relatedObject.name.translate(self.nameTranslator, recursive=True, topAncestor=commonName)
def translate_keyword(self, keyword):
......@@ -617,15 +616,21 @@ class SphinxTranslator(Translator):
ref=Translator.translate_reference(self, ref, absName=True)
)
def translate_function_reference(self, ref, label=None, namespace=None):
paramTypes = []
if self.domain != 'c':
for arg in ref.relatedObject.args:
paramTypes.append(arg._type.translate(self.langTranslator))
def translate_function_reference(self, ref, label=None, useNamespace=True, namespace=None):
if self.domain == 'csharp':
refStr = ref.relatedObject.name.translate(self.nameTranslator, **abstractapi.Translator._namespace_to_name_translator_params(namespace))
else:
refStr = ref.relatedObject.translate_as_prototype(self.langTranslator,
hideArguments=self.domain != 'java',
hideArgNames=self.domain == 'java',
hideReturnType=True,
stripDeclarators=True,
namespace=namespace
)
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))
ref=refStr
)
def 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