1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* signaturebuilder.vala
*
* Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Didier 'Ptitjes Villevalois <ptitjes@free.fr>
*/
using Valadoc.Content;
/**
* Builds up a signature from the given items.
*/
public class Valadoc.Api.SignatureBuilder {
private Run run;
private Inline last_appended;
/**
* Creates a new SignatureBuilder
*/
public SignatureBuilder () {
run = new Run (Run.Style.NONE);
}
private void append_text (string text) {
if (last_appended is Text) {
((Text) last_appended).content += text;
} else {
run.content.add (last_appended = new Text (text));
}
}
/**
* Adds text onto the end of the builder.
*
* @param text a string
* @param spaced add a space at the front of the string if necessary
* @return this
*/
public SignatureBuilder append (string text, bool spaced = true) {
string content = (last_appended != null && spaced ? " " : "") + text;
append_text (content);
return this;
}
/**
* Adds text onto the end of the builder.
*
* @param text a string
* @param spaced add a space at the front of the string if necessary
* @return this
*/
public SignatureBuilder append_attribute (string text, bool spaced = true) {
string content = (last_appended != null && spaced ? " " : "") + text;
append_text (content);
return this;
}
/**
* Adds highlighted text onto the end of the builder.
*
* @param text a string
* @param spaced add a space at the front of the string if necessary
* @return this
*/
public SignatureBuilder append_highlighted (string text, bool spaced = true) {
string content = (last_appended != null && spaced ? " " : "") + text;
Run inner = new Run (Run.Style.ITALIC);
inner.content.add (new Text (content));
return append_content (inner, spaced);
}
/**
* Adds a Inline onto the end of the builder.
*
* @param content a content
* @param spaced add a space at the front of the inline if necessary
* @return this
*/
public SignatureBuilder append_content (Inline content, bool spaced = true) {
if (last_appended != null && spaced) {
append_text (" ");
}
run.content.add (last_appended = content);
return this;
}
/**
* Adds a keyword onto the end of the builder.
*
* @param keyword a keyword
* @param spaced add a space at the front of the keyword if necessary
* @return this
*/
public SignatureBuilder append_keyword (string keyword, bool spaced = true) {
Run inner = new Run (Run.Style.LANG_KEYWORD);
inner.content.add (new Text (keyword));
return append_content (inner, spaced);
}
/**
* Adds a symbol onto the end of the builder.
*
* @param node a node
* @param spaced add a space at the front of the node if necessary
* @return this
*/
public SignatureBuilder append_symbol (Node node, bool spaced = true) {
Run inner = new Run (Run.Style.BOLD);
inner.content.add (new SymbolLink (node, node.name));
return append_content (inner, spaced);
}
/**
* Adds a type onto the end of the builder.
*
* @param node a node
* @param spaced add a space at the front of the node if necessary
* @return this
*/
public SignatureBuilder append_type (Node node, bool spaced = true) {
Run.Style style = Run.Style.LANG_TYPE;
if (node is TypeSymbol && ((TypeSymbol)node).is_basic_type) {
style = Run.Style.LANG_BASIC_TYPE;
}
Run inner = new Run (style);
inner.content.add (new SymbolLink (node, node.name));
return append_content (inner, spaced);
}
/**
* Adds a type name onto the end of the builder.
*
* @param name a type name
* @param spaced add a space at the front of the type name if necessary
* @return this
*/
public SignatureBuilder append_type_name (string name, bool spaced = true) {
Run inner = new Run (Run.Style.LANG_TYPE);
inner.content.add (new Text (name));
return append_content (inner, spaced);
}
/**
* Adds a literal onto the end of the builder.
*
* @param literal a literal
* @param spaced add a space at the front of the literal if necessary
* @return this
*/
public SignatureBuilder append_literal (string literal, bool spaced = true) {
Run inner = new Run (Run.Style.LANG_LITERAL);
inner.content.add (new Text (literal));
return append_content (inner, spaced);
}
/**
* The content
*/
public new Run get () {
return run;
}
}
|