Completed
Pull Request — master (#2423)
by
unknown
01:57
created

assemble_full_documentation()   B

Complexity

Conditions 3

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 31
rs 8.8571
1
from coalib.bearlib.languages.documentation.DocumentationComment import (
2
    DocumentationComment)
3
4
Description = DocumentationComment.Description
5
Parameter = DocumentationComment.Parameter
6
ReturnValue = DocumentationComment.ReturnValue
7
8
9
def assemble_documentation(doccomment, param_sym, ret_sym):
10
    """
11
    Assembles a list of parsed documentation comments.
12
13
    This function just assembles the documentation comment
14
    itself, without the markers and indentation.
15
16
    :param doccomment:
17
        The list of parsed documentation comments.
18
    :param param_sym:
19
        A two element tuple that defines how a param definition starts and
20
        ends in a documentation comment.
21
    :param ret_sym:
22
        A string that defines how a return statement definition occurs in
23
        a documentation comment.
24
    """
25
    assembled_doc = ""
26
    for section in doccomment:
27
        section_desc = section.desc.splitlines(keepends=True)
28
        if isinstance(section, Description):
29
            assembled_doc += section_desc[0]
30
        elif isinstance(section, Parameter):
31
            assembled_doc += (param_sym[0] + section.name + param_sym[1] +
32
                              section_desc[0])
33
        elif isinstance(section, ReturnValue):
34
            assembled_doc += ret_sym + section_desc[0]
35
        for desc in section_desc[1:]:
36
            if desc != "":
37
                assembled_doc += desc
38
    return assembled_doc
39
40
41
def assemble_full_documentation(doccomment, param_sym, ret_sym,
42
                                markers, indent):
43
    """
44
    Assembles a list of parsed documentation comments.
45
46
    This function assembles the whole documentation comment,
47
    with the given markers and indentation.
48
49
    :param doccomment:
50
        The list of parsed documentation comments.
51
    :param param_sym:
52
        A two element tuple that defines how a param definition starts and
53
        ends in a documentation comment.
54
    :param ret_sym:
55
        A string that defines how a return statement definition occurs in
56
        a documentation comment.
57
    :param markers:
58
        The markers to be used.
59
    :param indent:
60
        The indentation level to be used for each line of the documentation
61
        comment.
62
    """
63
    assembled_doc = assemble_documentation(doccomment, param_sym, ret_sym)
64
    assembled_doc = assembled_doc.splitlines(keepends=True)
65
    assembled = indent + markers[0]
66
    for section in assembled_doc:
67
        if section == "\n":
68
            assembled += '\n'
69
        else:
70
            assembled += indent + markers[1] + section
71
    return assembled + indent + markers[2]
72