Eclipseのコード補完でコーディングを楽にしよう。
Eclipseにはコーディングを楽にするためにコンテンツアシストという機能があります。
コンテンツアシストは、Javaエディタ上で「Ctrl+Space」を押すことで使用でき、クラス名のメソッド名など、何かと補完してくださるありがたい機能です。
また、コーディングパターンをJavaエディタのテンプレートとして登録しておくことで、そのテンプレートからソースコードの補完もできます。
このテンプレートをうまく使いこなすために、デフォルトで組み込まれているJavaコードのテンプレートを調べてみました。
なお、テンプレートは新たに追加登録することが可能です。
設定
Javaエディタのテンプレートは以下の場所で編集、追加、削除ができます。
「Window」→「Preferences」
「Preferences」 → 「Java」 → 「Editor」 → 「Templates」
コンテキスト
Javaエディタのテンプレートは以下のコンテキストを持ち、テンプレートが有効になる範囲を定義します。
使い方
テンプレートの使用はテンプレートの名前を入力してコンテンツアシスト(「Ctrl+Space」)を行うとテンプレートの候補される。
以下の図のように右のポップアップには補完時のコードが表示される。
Enterを押すと表示されていた内容が補完される。
テンプレート
以下にコンテキストごとに、デフォルトで含まれているテンプレートの名前と説明を列挙します。
Javadoc
名前 | 説明 |
---|---|
@author | author name |
<b> | <b></b> |
<code> | <code></code> |
<i> | <i></i> |
<pre> | <pre></pre> |
active_task | active task |
false | <code>false</code> |
null | <code>null</code> |
true | <code>true</code> |
Java
名前 | 説明 |
---|---|
catch | catch block |
fall-through | $FALL-THROUGH$ marker |
nls | non-externalized string marker |
runnable | runnable |
toarray | convert collection to array |
Java type members
名前 | 説明 |
---|---|
main | main method |
private_method | private method |
private_static_method | private static method |
protected_method | protected method |
public_method | public method |
static_final | static final field |
test | test method |
Test | test method (JUnit 4) |
Java statements
名前 | 説明 |
---|---|
arrayadd | add an element to an array |
arraymerge | merge two arrays into one |
cast | dynamic cast |
do | do while statement |
else | else block |
elseif | else if block |
for | iterate over array |
for | iterate over array with temporary variable |
for | iterate over collection |
foreach | iterate over an array or Iterable |
if | if statement |
ifelse | if else statement |
instanceof | dynamic type test and cast |
lazy | lazy creation |
new | create new object |
switch | switch case statement |
synchronized | synchronized block |
syserr | print to standard error |
sysout | print to standard out |
systrace | print current method to standard out |
try | try catch block |
while | iterate with enumeration |
while | iterate with iterator |
while | while loop with condition |
SWT statements
名前 | 説明 |
---|---|
addlistener | add a listener to a Widget |
Browser | new Browser |
Button | new Button |
Combo | new Combo |
Composite | new Composite with GridLayout |
DateTime | new DateTime |
execute | execute a runnable in the UI thread |
ExpandBar | new ExpandBar |
ExpandItem | new ExpandItem for an ExpandBar |
GridData | new GridData for a Control |
GridLayout | new GridLayout for a Composites |
Group | new Group with GridLayout |
Image | new Image |
Label | new Label |
Link | new Link |
List | new List |
mainloop | new top level Shell with event loop |
SashForm | new SashForm |
Scale | new Scale |
ScrolledComposite | new ScrolledComposite |
Shell | new Shell |
Spinner | new Spinner |
StyledText | new StyledText |
StyleRange | new StyleRange for a StyledText |
TabFolder | new TabFolder |
TabItem | new TabItem for a TabFolder |
Table | new Table |
TableColumn | new TableColumn for a Table |
TableItem | new TableItem for a Table |
Text | new Text |
ToolBar | new ToolBar |
ToolItem | new ToolItem for a ToolBar |
Tree | new Tree |
TreeColumn | new TreeColumn for a Tree |
TreeItem | new TreeItem for a Tree |