Jump to: navigation, search

Difference between revisions of "FAQ How can templates make me the fastest coder ever?"

(See Also)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The Eclipse editor framework has excellent support for templates,  
+
The Eclipse editor framework has excellent support for templates, and we don't mean the C++ kind.  
and we don’t mean the C++ kind.  
+
  
 +
In Eclipse, templates are fragments of code that can be inserted in an editor to ease the entering of repetitive code.  Code templates are accessed and used in the same way as Content Assist.  In the following example, we entered <tt>'''for'''</tt>, then pressed Ctrl+Space. We chose '''iterate over array with temporary value''' and pressed the Tab key to advance to the first variant in the inserted template (Figure 3.1). When we enter a new name for the index variable, all occurrences in the template are automatically changed also.
  
 +
Another powerful, and quite useful, example is the following: Select a couple of statements, press Ctrl+Space and select '''try catch block''' to encapsulate the current selection with an exception handler.
  
In Eclipse, templates are fragments of code that can be inserted in
+
New templates can also be defined. Templates can be imported and exported, allowing them to be shared among multiple developers in a team.
an editor to ease the entering of repetitive code.  
+
Code templates are accessed and used in the same way as Content Assist.
+
In the following example, we entered <tt>'''for'''</tt>, then
+
pressed Ctrl+Space. We chose '''iterate over array with temporary
+
value''' and pressed the Tab key to advance to the first variant in  
+
the inserted template (Figure 3.1). When we enter a new name for the index
+
variable, all occurrences in the template are automatically changed also.
+
  
 +
See '''Window > Preferences > Java > Editor > Templates''' and press F1 for relevant help on this topic.
  
 +
== See Also ==
  
&nbsp;&nbsp;&nbsp;&nbsp;<img src=../images/templates.png>
+
* [[FAQ_How_can_Content_Assist_make_me_the_fastest_coder_ever?]]
  
 
+
{{Copyright|locationhref=http://www.eclipsefaq.org|location=Official Eclipse 3.0 FAQs|year=2004|holder=Pearson Education, Inc}}
&nbsp;&nbsp;&nbsp;&nbsp;'''Figure 3.1'''&nbsp;&nbsp;
+
After inserting the <tt>for</tt> loop template
+
 
+
 
+
 
+
Another powerful, and quite useful, example is the following: Select a couple
+
of statements, press Ctrl+Space and select '''try catch block''' to
+
encapsulate the current selection with an exception handler.
+
 
+
 
+
 
+
New templates can also be defined. Templates can be imported and
+
exported, allowing them to be shared among multiple developers in a team.
+
 
+
 
+
 
+
See '''Window &gt; Preferences &gt; Java &gt; Editor &gt; Templates''' and
+
press F1 for relevant help on this topic.
+
 
+
 
+
 
+
 
+
 
+
== See Also: ==
+
 
+
 
+
[[FAQ_How_can_Content_Assist_make_me_the_fastest_coder_ever%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Latest revision as of 22:09, 22 August 2007

The Eclipse editor framework has excellent support for templates, and we don't mean the C++ kind.

In Eclipse, templates are fragments of code that can be inserted in an editor to ease the entering of repetitive code. Code templates are accessed and used in the same way as Content Assist. In the following example, we entered for, then pressed Ctrl+Space. We chose iterate over array with temporary value and pressed the Tab key to advance to the first variant in the inserted template (Figure 3.1). When we enter a new name for the index variable, all occurrences in the template are automatically changed also.

Another powerful, and quite useful, example is the following: Select a couple of statements, press Ctrl+Space and select try catch block to encapsulate the current selection with an exception handler.

New templates can also be defined. Templates can be imported and exported, allowing them to be shared among multiple developers in a team.

See Window > Preferences > Java > Editor > Templates and press F1 for relevant help on this topic.

See Also


This page was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.