1 /* signaturebuilder.vala
3 * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
24 using Valadoc
.Content
;
27 * Builds up a signature from the given items.
29 public class Valadoc
.Api
.SignatureBuilder
{
31 private Inline last_appended
;
34 * Creates a new SignatureBuilder
36 public SignatureBuilder () {
37 run
= new
Run (Run
.Style
.NONE
);
40 private void append_text (string text
) {
41 if (last_appended is Text
) {
42 ((Text
) last_appended
).content
+= text
;
44 run
.content
.add (last_appended
= new
Text (text
));
49 * Adds text onto the end of the builder.
51 * @param text a string
52 * @param spaced add a space at the front of the string if necessary
55 public unowned SignatureBuilder
append (string text
, bool spaced
= true) {
56 string content
= (last_appended
!= null && spaced ?
" " : "") + text
;
57 append_text (content
);
62 * Adds text onto the end of the builder.
64 * @param text a string
65 * @param spaced add a space at the front of the string if necessary
68 public unowned SignatureBuilder
append_attribute (string text
, bool spaced
= true) {
69 string content
= (last_appended
!= null && spaced ?
" " : "") + text
;
70 append_text (content
);
75 * Adds highlighted text onto the end of the builder.
77 * @param text a string
78 * @param spaced add a space at the front of the string if necessary
81 public unowned SignatureBuilder
append_highlighted (string text
, bool spaced
= true) {
82 string content
= (last_appended
!= null && spaced ?
" " : "") + text
;
83 Run inner
= new
Run (Run
.Style
.ITALIC
);
84 inner
.content
.add (new
Text (content
));
85 return append_content (inner
, spaced
);
89 * Adds a Inline onto the end of the builder.
91 * @param content a content
92 * @param spaced add a space at the front of the inline if necessary
95 public unowned SignatureBuilder
append_content (Inline content
, bool spaced
= true) {
96 if (last_appended
!= null && spaced
) {
99 run
.content
.add (last_appended
= content
);
104 * Adds a keyword onto the end of the builder.
106 * @param keyword a keyword
107 * @param spaced add a space at the front of the keyword if necessary
110 public unowned SignatureBuilder
append_keyword (string keyword
, bool spaced
= true) {
111 Run inner
= new
Run (Run
.Style
.LANG_KEYWORD
);
112 inner
.content
.add (new
Text (keyword
));
113 return append_content (inner
, spaced
);
117 * Adds a symbol onto the end of the builder.
120 * @param spaced add a space at the front of the node if necessary
123 public unowned SignatureBuilder
append_symbol (Node node
, bool spaced
= true) {
124 Run inner
= new
Run (Run
.Style
.BOLD
);
125 inner
.content
.add (new
SymbolLink (node
, node
.name
));
126 return append_content (inner
, spaced
);
130 * Adds a type onto the end of the builder.
133 * @param spaced add a space at the front of the node if necessary
136 public unowned SignatureBuilder
append_type (Node node
, bool spaced
= true) {
137 Run
.Style style
= Run
.Style
.LANG_TYPE
;
138 if (node is TypeSymbol
&& ((TypeSymbol
)node
).is_basic_type
) {
139 style
= Run
.Style
.LANG_BASIC_TYPE
;
142 Run inner
= new
Run (style
);
143 inner
.content
.add (new
SymbolLink (node
, node
.name
));
144 return append_content (inner
, spaced
);
148 * Adds a type name onto the end of the builder.
150 * @param name a type name
151 * @param spaced add a space at the front of the type name if necessary
154 public unowned SignatureBuilder
append_type_name (string name
, bool spaced
= true) {
155 Run inner
= new
Run (Run
.Style
.LANG_TYPE
);
156 inner
.content
.add (new
Text (name
));
157 return append_content (inner
, spaced
);
161 * Adds a literal onto the end of the builder.
163 * @param literal a literal
164 * @param spaced add a space at the front of the literal if necessary
167 public unowned SignatureBuilder
append_literal (string literal
, bool spaced
= true) {
168 Run inner
= new
Run (Run
.Style
.LANG_LITERAL
);
169 inner
.content
.add (new
Text (literal
));
170 return append_content (inner
, spaced
);
176 public new Run
get () {