Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change auto-generated code when creating new class in Eclipse

Tags:

java

eclipse

Whenever I create a new Java file in Eclipse and check off the option to add public static void main(String args[]), this code is generated:

public class Test {      /**      * @param args      */     public static void main(String[] args) {         // TODO Auto-generated method stub      }  } 

How do i:

  • Remove the @param args comment
  • Change the indentation so each { is on a line of its own
  • Remove the TODO auto generated comment
like image 669
Ali Avatar asked Feb 01 '09 21:02

Ali


People also ask

How do I get rid of Todo auto generated method stub?

If you also don't like the TODO comments you can change the templates via: Window -> Preferences -> Java -> Code Style -> Code Templates. In the code tree you have the templates. Select for example Code → Method Body and press “Edit” to edit this template and to remove the todo comment.

How do I change the default author in eclipse?

Simply go to: Window - Preferences - Java - Code Style - Code Templates - Comments - Types - Edit... and change ${user} to whatever you want. Also go to: Window - Preferences - Java - Editor - Templates - @author - Edit... and change ${user} to whatever you want.

How do I find class code in Eclipse?

Go to Windows->Preferences->Java->Installed JREs. Select Browse and navigate to the C:\Program Files\Java\jdk1. 6.0_21 directory. Eclipse will automatically find the source and associate it with the JDK classes.


2 Answers

The indention is a formatting issue while the comments is a template issue.

The templates are in Window -> Preferences -> Java -> Code Style -> Code Templates. Browse all of them and look for the things you would like to change.

The Formatter is a little bit more complicated. You find it under Window -> Preferences -> Java -> Code Style -> Formatter. There are tons of options there but I'll just answer your question.

  • Templates -> Comments -> Methods -> Edit and delete everything
  • Formatter -> Edit -> Braces Tab -> Change which situations you want
  • Templates -> Code -> Method Body -> Edit and delete everything
like image 150
pek Avatar answered Oct 13 '22 00:10

pek


  1. In Eclipse Go to Window->Preferences
  2. In Left Panel, Select Java->Code Style->Code Template
  3. Under "Configure generated code and comments", Expand Comments-> select Methods,Click Edit Remove or replace the pattern ( * @param args),Click OK
  4. Under "Configure generated code and comments", Expand Code-> select Method Body,Click Edit Remove or replace the pattern ( // TODO Auto-generated...),Click OK
  5. Click OK !
like image 38
Bhanuprakasha Avatar answered Oct 13 '22 02:10

Bhanuprakasha