Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

EclipseのJavaエディタ用のテンプレートを追加

EclipseJavaエディタ用のテンプレートを追加する方法について。

メニューからウインドウ→設定→Java→エディタ→テンプレート
を選択。新規ボタンを押下。
名前にコード補完時に入力したい値
説明に説明内容
パターンにテンプレートの内容を記述

以下は、サンプルとして引数が1個のメソッドのテンプレートを作成。

/**
* ${method_name} ${method_name_ja}.
*
* <pre>
* ${method_description}.
* </pre>
*
* @param ${param1} ${param1_description}
* @return ${return_type} ${return_type_description}
* @exception ${Exception}
*/
private ${return_type} ${method_name}(${param1_type} ${param1}) throws ${Exception} {
${return_type} ${return_name} = null;
${line_selection}
return ${return_name};
}

登録後、methまで入力してCtrl+Spaceを入力すれば以下のように出力されます。
変数名や、データ型などの部分は入力→Tab→入力・・・で素早く設定できるようになっています。

    /**
* method_name method_name_ja.
*
* <pre>
* method_description.
* </pre>
*
* @param param1 param1_description
* @return return_type return_type_description
* @exception Exception
*/
private return_type method_name(param1_type param1) throws Exception {
return_type return_name = null;

return return_name;
}