@@ -63,39 +63,52 @@ func (code *Code) FuncEnd() *Code {
6363 return code
6464}
6565
66- // Block End
66+ // BlockEnd adds a block ending to code: }\n.
6767func (code * Code ) BlockEnd () * Code {
68+ // Return nil in case code is nil
6869 if code == nil {
6970 return nil
7071 }
72+ // Add a block ending to code
7173 code .c += "}\n "
74+ // Return code
7275 return code
7376}
7477
75- // Function Call
78+ // Call adds a function call to code: n(. The function name is
79+ // provided by n.
7680func (code * Code ) Call (n string ) * Code {
81+ // Return nil in case code is nil
7782 if code == nil {
7883 return nil
7984 }
85+ // Add a function call to code
8086 code .c += fmt .Sprintf ("%v(" , n )
87+ // Return code
8188 return code
8289}
8390
84- // Parameters End + new line
91+ // ParamEndln adds a parameters ending and a new line to code: )\n.
8592func (code * Code ) ParamEndln () * Code {
93+ // Return nil in case code is nil
8694 if code == nil {
8795 return nil
8896 }
97+ // Add a parameters ending and a new line to code
8998 code .c += ")\n "
99+ // Return code
90100 return code
91101}
92102
93- // Parameters End
103+ // ParamEnd adds a parameters ending to code: ).
94104func (code * Code ) ParamEnd () * Code {
105+ // Return nil in case code is nil
95106 if code == nil {
96107 return nil
97108 }
109+ // Add parameters ending to code
98110 code .c += ")"
111+ // Return code
99112 return code
100113}
101114
@@ -111,65 +124,97 @@ func (code *Code) Func1(a *Func1Args) *Code {
111124 return code
112125}
113126
114- // Type declaration for struct type
127+ // TypeStruct adds a type declaration for a struct type to code: type n struct {\n.
128+ // The name of the type is provided with n.
115129func (code * Code ) TypeStruct (n string ) * Code {
130+ // Return nil in case code is nil
116131 if code == nil {
117132 return nil
118133 }
134+ // Add a type declaration for a struct type to code
119135 code .c += fmt .Sprintf ("type %v struct {\n " , n )
136+ // Return code
120137 return code
121138}
122139
123- type TypeArgs struct {
124- Name , Type string
140+ // VarSpecArgs contains the identifier Ident and type Type to generate
141+ // a variable specification with VarSpec
142+ type VarSpecArgs struct {
143+ Ident , Type string
125144}
126145
127- // Type
128- func (code * Code ) Type (a * TypeArgs ) * Code {
146+ // VarSpec adds a variable specification to code: Ident Type\n. The identifier and type
147+ // is provided by a.
148+ func (code * Code ) VarSpec (a * VarSpecArgs ) * Code {
149+ // Return nil in case code is nil
129150 if code == nil {
130151 return nil
131152 }
132- code .c += fmt .Sprintf ("%v %v\n " , a .Name , a .Type )
153+ // Add a variable specification to code
154+ code .c += fmt .Sprintf ("%v %v\n " , a .Ident , a .Type )
155+ // Return code
133156 return code
134157}
135158
136- // IdentifierLIst
159+ // List adds an identifier list to code: , .
137160func (code * Code ) List () * Code {
161+ // Return nil in case code is nil
138162 if code == nil {
139163 return nil
140164 }
165+ // Add an identifier list to code
141166 code .c += ", "
167+ // Return code
142168 return code
143169}
144170
145- // IdentifierList with new line
171+ // Listln adds an identifier list and a new line to code: ,\n.
146172func (code * Code ) Listln () * Code {
173+ // Return nil in case code is nil
147174 if code == nil {
148175 return nil
149176 }
177+ // Add an identifier list and a new line to code
150178 code .c += ",\n "
179+ // Return code
151180 return code
152181}
153182
154183type SelArgs struct {
155184 Val , Sel string
156185}
157186
158- // Field Selector
187+ // SelField adds a field selector to code: val.sel. The value val and selector sel are
188+ // provided by a. It returns nil if a is nil.
159189func (code * Code ) SelField (a * SelArgs ) * Code {
190+ // Return nil in case code is nil
160191 if code == nil {
161192 return nil
162193 }
194+ // Return nil in case a is nil
195+ if a == nil {
196+ return nil
197+ }
198+ // Add a field selector to code
163199 code .c += fmt .Sprintf ("%v.%v" , a .Val , a .Sel )
200+ // Return code
164201 return code
165202}
166203
167- // Method Selector
204+ // SelMethod adds a method selector to code: val.sel(. The value val and selector sel are
205+ // provided by a. It returns nil if a is nil.
168206func (code * Code ) SelMethod (a * SelArgs ) * Code {
207+ // Return nil in case code is nil
169208 if code == nil {
170209 return nil
171210 }
211+ // Return nil in case a is nil
212+ if a == nil {
213+ return nil
214+ }
215+ // Add a method selector to code
172216 code .c += fmt .Sprintf ("%v.%v(" , a .Val , a .Sel )
217+ // Return code
173218 return code
174219}
175220
@@ -259,7 +304,7 @@ type ShortVarDeclArgs struct {
259304}
260305
261306// ShortVarDecl generates a short variable declaration: Ident := Expr\n. The identifier
262- // and expression is provided by a.
307+ // and expression is provided by a. It returns nil if a is nil.
263308func (code * Code ) ShortVarDecl (a * ShortVarDeclArgs ) * Code {
264309 // Return nil in case code is nil
265310 if code == nil {
@@ -282,7 +327,7 @@ type KeyedElementArgs struct {
282327}
283328
284329// KeyedElement generates a keyed element of a composite literal: Key: Element,\n. The key and element
285- // is provided by a.
330+ // is provided by a. It returns nil if a is nil.
286331func (code * Code ) KeyedElement (a * KeyedElementArgs ) * Code {
287332 // Return nil in case code is nil
288333 if code == nil {
@@ -306,6 +351,7 @@ type Testvars struct {
306351
307352// Testvariables generates test variables for unit tests. The test variables are generated based
308353// on t. A test variable is generated if the corresponding type in t is not equal to zero.
354+ // It returns nil if t is nil.
309355func (code * Code ) Testvariables (t * Testvars ) * Code {
310356 // Return nil in case code is nil
311357 if code == nil {
0 commit comments