Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is ${body_statement} defined in Eclipse

Tags:

java

eclipse

In Eclipse Luna, I want to change the content of the autogenerated methods, so I went to Window->Preferences->Java->Code Style->Code Templates->Code->Method body and I saw there this declaration:

// ${todo} Auto-generated method stub
${body_statement}

Is it possible to to change the ${body_statement} content?

Edit: @Duncan - I don't want my generated methods to return null but I want them to throw an exception that the method is not implemented. The reason why I want to change the ${body_statement} is because I want to change all occurrences by one edit and I don't want to go through all templates and inspect them one by one.

like image 648
Michal Krasny Avatar asked Mar 13 '15 09:03

Michal Krasny


2 Answers

Just delete the invocation of ${body_statement} in your template

Here is my Method Body template which adds a TODO and an exception should the method be called:

// ${todo} Implement ${enclosing_type}.${enclosing_method}
throw new RuntimeException("Unimplemented Method    ${enclosing_type}.${enclosing_method} invoked.");

Which when invokded after writing

int foo = doSomething();

Generates:

private int doSomething() {
    // TODO Implement ScaledFraction.doSomething
    throw new RuntimeException("Unimplemented Method ScaledFraction.doSomething invoked.");

}
like image 51
Roger Neyman Avatar answered Sep 23 '22 19:09

Roger Neyman


${body_statement} is a "variable". Click on "Edit..." at the right side of the Code Templates list to edit a code template and use "Insert Variable..." to see a list of available variables.

The ${body_statement} variable is actually empty for new methods. If you want to provide some default-code for each new method, you can simple add that text above the ${body_statement}.

Adding real code below the variable in that template will not work, since ${body_statement} will be replaced by a return statement in some cases.

like image 30
slartidan Avatar answered Sep 23 '22 19:09

slartidan