Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7172549b87947bfb23197ae8ea94f48373e6cdf3 (plain) (blame)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html lang="en">
  <head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2007. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>
      Code templates
    </title>
    <link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
    <script language="JavaScript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js"> </script>
  </head>
  <body>
    <div role="main"><h1>
      Code templates
    </h1>
<p>The
<img src="../images/command_link.png" alt="" > <a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.cdt.ui.preferences.CodeTemplatePreferencePage)")'>
Code Templates</a> preference panel lets you configure the format of newly generated code stubs, comments and files.</p>
<p><img src="../images/pref_panel_code_templates.png" alt="Code Templates Preferences Window"></p>

<p>The code templates page contains templates that are used by actions that generate code and/or source files. 
E.g. the New Class wizard uses source and header file templates to create new files and code templates to insert generated method stubs. 
Templates contain variables that are substituted when the template is applied. Some variables are available in all templates, some are specific to templates.</p><table
	border="1" cellspacing="0" cellpadding="5" width="600">
	<thead>
		<tr>
			<th id="option">
			<strong>Options</strong>
			</th>
			<th id="description">
			<strong>Description</strong>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" style="width: 25%;" headers="option">
			<strong>New...</strong>
			</td>
			<td valign="top" headers="description">
			<p>Opens the Code Template dialog to create a new file template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="option">
			<strong>Edit...</strong>
			</td>
			<td valign="top" headers="description">
			<p>Opens the Code Template dialog to edit the currently selected code template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="option">
			<strong>Remove</strong>
			</td>
			<td valign="top" headers="description">
			<p>Removes a user added file template. Predefined templates cannot be removed.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option">
			<strong>Import...</strong>
			</td>
			<td valign="top" headers="description">
			<p>Imports templates from the file system.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option">
			<strong>Export...</strong>
			</td>
			<td valign="top" headers="description">
			<p>Exports all selected templates to the file system.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option">
			<strong>Export All...</strong>
			</td>
			<td valign="top" headers="description">
			<p>Exports all templates to the file system.</p>
			</td>
		</tr>
	</tbody>
</table>


<h2>Comment Templates</h2>

<table border="1" cellspacing="0" cellpadding="5" width="600">
	<thead>
		<tr>
			<th id="template">
			<strong>Template Name</strong>
			</th>
			<th id="specifies">
			<strong>Specifies</strong>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Files</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>Header comment for new source or header files.</p>
			<p>Note that this template can be referenced in source and header file templates with <strong>${filecomment}</strong>.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Types</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>The comment for new types.</p>
			<p>Note that this template can be referenced in source and header file templates with <strong>${typecomment}</strong>.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Fields</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>The comment for new fields.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Constructors</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>The comment for new constructors.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Destructors</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>The comment for new destructors.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template">
			<strong>Methods</strong>
			</td>
			<td valign="top" headers="specifies">
			<p>The comment for new methods.</p>
			</td>
		</tr>
	</tbody>
</table>

<h2>Code Templates</h2>
<br>
<table
	border="1" cellspacing="0" cellpadding="5" width="600">
	<thead>
		<tr>
			<th id="template2">
			<strong>Template Name</strong>
			</th>
			<th id="description2">
			<strong>Description</strong>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" style="width: 25%;" headers="template2">
			<strong>Method body</strong>
			</td>
			<td valign="top" headers="description2">
			<p>The 'Method body' templates are used when new method is created.</p> 
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template2">
			<strong>Constructor body</strong>
			</td>
			<td valign="top" headers="description2">
			<p>The 'Constructor body' templates are used when a constructor is created.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template2">
			<strong>Destructor body</strong>
			</td>
			<td valign="top" headers="description2">
			<p>The 'Destructor body' templates are used when the destructor is created.</p>
			</td>
	</tbody>
</table>

<h2>File Templates</h2>
File templates can not only be defined and modified for C/C++ files, but also for other content types, like Assembly files or plain text files.
The New File from Template wizard can be used to create new files based on one of the templates defined in this page.
<br>
<table
	border="1" cellspacing="0" cellpadding="5" width="600">
	<thead>
		<tr>
			<th id="template3">
			<strong>Template Name</strong>
			</th>
			<th id="description3">
			<strong>Description</strong>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" style="width: 25%;" headers="template3">
			<strong>Default C++ source template</strong>
			</td>
			<td valign="top" headers="description3">
			<p>Used by the New Class wizard and the New Source File wizard when a new C++ source file is created.</p> 
			<p>The template can specify where comments are added. Note that the template can contain the variable <strong>${typecomment}</strong> and <strong>${filecomment}</strong> that will be substituted by the evaluation of the <strong>Types</strong> respectively <strong>Files</strong> comment template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template3">
			<strong>Default C++ header template</strong>
			</td>
			<td valign="top" headers="description3">
			<p>Used by the New Class wizard and the New Header File wizard when a new C++ header file is created.</p> 
			<p>The template can specify where comments are added. Note that the template can contain the variable <strong>${typecomment}</strong> and <strong>${filecomment}</strong> that will be substituted by the evaluation of the <strong>Types</strong> respectively <strong>Files</strong> comment template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template3">
			<strong>Default C source template</strong>
			</td>
			<td valign="top" headers="description3">
			<p>Used by the New Source File wizard when a new C source file is created.</p> 
			<p>The template can specify where comments are added. Note that the template can contain the variable <strong>${typecomment}</strong> and <strong>${filecomment}</strong> that will be substituted by the evaluation of the <strong>Types</strong> respectively <strong>Files</strong> comment template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template3">
			<strong>Default C header template</strong>
			</td>
			<td valign="top" headers="description3">
			<p>Used by the New Header File wizard when a new C source file is created.</p> 
			<p>The template can specify where comments are added. Note that the template can contain the variable <strong>${typecomment}</strong> and <strong>${filecomment}</strong> that will be substituted by the evaluation of the <strong>Types</strong> respectively <strong>Files</strong> comment template.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" style="width: 25%;" headers="template3">
			<strong><em>Other file templates</em></strong>
			</td>
			<td valign="top" headers="description3">
			<p>File templates can be defined for other content types, e.g. Assembly or plain text.</p> 
			</td>
		</tr>
	</tbody>
</table>

<h2>Edit Template dialog</h2>
<p><img src="../images/pref_panel_edit_template_dlg.png" alt="Edit Template Dialog Box"></p>

<p>The following fields and buttons appear in the dialog:</p>
<table border="1" cellspacing="0" cellpadding="5" width="600">
	<thead>
		<tr>
			<th id="option4">
			<strong>Options</strong>
			</th>
			<th id="description4">
			<p>Description</p>
			</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td valign="top" headers="option4">
			<strong>Name</strong>
			</td>
			<td valign="top" headers="description4">
			<p>The name of the template. Only available for file templates.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option4">
			<strong>Type</strong>
			</td>
			<td valign="top" headers="description4">
			<p>The file type (content type) of the template. Only available for file templates.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option4">
			<strong>Description</strong>
			</td>
			<td valign="top" headers="description4">
			<p>A description of the template</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option4">
			<strong>Pattern</strong>
			</td>
			<td valign="top" headers="description4">
			<p>The template pattern.</p>
			</td>
		</tr>
		<tr>
			<td valign="top" headers="option4">
			<strong>Insert Variables...</strong>
			</td>
			<td valign="top" headers="description4">
			<p>Displays a list of pre-defined template specific variables.</p>
			</td>
		</tr>
	</tbody>
</table>

<p><img src="../images/ngconcepts.gif" ALT="Related concepts" width="143" height="21"> <br>
<a href="../concepts/cdt_o_code_entry.htm">Coding aids</a></p>
<p><img src="../images/ngref.gif" ALT="Related reference" width="143" height="21">
<br>
<a href="cdt_o_ceditor_pref.htm">C/C++ editor preferences</a></p>
<img src="../images/ng00_07.gif" ALT="IBM Copyright Statement" >

</div></body>
</html>

Back to the top