更新時間:2020-09-28 17:22:55 來源:動力節(jié)點(diǎn) 瀏覽1805次
Eclipse是著名的跨平臺的自由集成開發(fā)環(huán)境(IDE),同時,Eclipse也是一個開放源代碼的、基于Java的可擴(kuò)展開發(fā)平臺。Eclipse之所以備受廣大開發(fā)人員的青睞,除了Eclipse的免費(fèi)使用,還有其強(qiáng)大的功能支持。除此之外,Eclipse靈活方便的快捷鍵也為eclipse帶來了許多優(yōu)質(zhì)的評價。當(dāng)然,既然有快捷鍵的存在,為了避免出現(xiàn)代碼混亂的情況,注釋的存在是不可避免的。下面就為小伙伴們帶來eclipse快捷鍵注釋的幾種方法。
一、多行注釋快捷鍵
1.選中你要加注釋的區(qū)域,用 Ctrl+Shift+C 或者 Ctrl+/ 會加上 // 注釋,再重復(fù)按一下就會去掉 // 注釋。(.js文件中只有 Ctrl+Shift+C 管用,.java文件中都管用)
2.選中你要加注釋的區(qū)域,用 Ctrl+shit+/ 會加上 /*...*/ 注釋,再用 Ctrl+shit+\ 會去掉 /*...*/ 注釋。(注意:正斜杠是加注釋,反斜杠是去掉注釋)
3.要修改在eclispe中的命令的快捷鍵方式我們只需進(jìn)入 Windows -> Preferences -> General -> keys 設(shè)置就行。
二、Eclipse中添加文檔注釋快捷鍵
1.例如默認(rèn)的文檔注釋:
/**
* @author xxx
*
*
*/
2.快捷鍵為:Alt+Shift+J
3.修改文檔注釋的注釋格式內(nèi)容,修改的方法有兩種:
A.直接在eclipse給的模板下進(jìn)行修改
打開Eclipse
Window --> Preferences --> Java --> Code Style --> Code Templates --> Comments --> types --> Edit...
例如:
/**
* 項目名稱:${project_name}
* 類名稱:${type_name}
* 類描述:
* 創(chuàng)建人:${user}
* 創(chuàng)建時間:${date} ${time}
* @version
*/
B.自己編寫一個xml文檔導(dǎo)入進(jìn)去
打開Eclipse
Window --> Preferences --> Java --> Code Style --> Code Templates --> Comments --> types --> Import...
選擇你寫好的模板.xml文件
Eclipse中默認(rèn)的模板.xml文件如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/** * ${tags} */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/** * @author ${user} * * ${tags} */ </template><template autoinsert="true" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/** * */</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/** * @param ${param} the ${bare_field_name} to set */</template><template autoinsert="true" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/** * */</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/** * @return the ${bare_field_name} */</template><template autoinsert="true" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/** * ${tags} */</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/** * ${tags} * ${see_to_target} */</template><template autoinsert="true" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/* (non-Javadoc) * ${see_to_overridden} */</template></templates> 自己寫好的模板.xml文件如下: <?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment"/><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment"> /** * Description: * @author hp DateTime ${date} ${time} * ${tags} */ </template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment"> /** * Description: * @author hp DateTime ${date} ${time} * ${tags} */</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment"> /** * Description: * @author hp DateTime ${date} * */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment"> /** * Class Name: ${file_name} * Description: * @author hp DateTime ${date} ${time} * @company bvit * @email [email protected] * @version 1.0 * ${tags} */</template><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment"> /** * @return get ${bare_field_name} */</template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment"> /** * Description: * @author hp DateTime ${date} ${time} * ${tags} */</template><template autoinsert="false" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment"> /** * Description: * @author hp DateTime ${date} * ${tags} * ${see_to_target} */</template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment"> /** * @param ${param} set ${bare_field_name} */</template></templates>
以上就是eclipse快捷鍵注釋的方法,小伙伴們可以根據(jù)實(shí)際情況選擇適合自己的方法。其實(shí),對于許多Java初學(xué)者來說,有正確的指導(dǎo)方法是至關(guān)重要的,這就像是黑暗中的引路人,現(xiàn)在,這樣的引路人就出現(xiàn)在本站的Java零基礎(chǔ)入門教程中,小伙伴們還在等什么,趕快行動吧,學(xué)習(xí)Java,從現(xiàn)在開始!
初級 202925
初級 203221
初級 202629
初級 203743