简体   繁体   中英

Can Eclipse auto-generate Java comments at the end of a method?

More specifically, can it generate a commend that is simply the name of the method? For example, for the main method:

public static void main(String[] args) {
    System.out.println("ping");
}//main  <--This comment, that has the name of the method

For generated methods only (will not work on existing ones): Preferences - Java - Templates:

Find the templates for method generation and edit them to your needs (insert comments after the closing bracket using the name-variable).

Example:

private ${return_type} ${name}(${}) {
    ${cursor}
}// ${name}

If you are looking to add this to every method ( hand written & generated) you will have to use some code formatting tool like Jalopy

There is a nice eclipse plugin for Jalopy by which you can apply your formatting rules on current file or across packages.

See this incarnation of Jalopy has exactly what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM