1

I watched the question about Eclipse -> Java -> Templates and how to create template to decrease code time development but I couldn't find how to:

  • generate template on Java class created
  • generate the template for some special Java classes which extend javax.swing.JPanel

for example how to generate code like :

public class AClass extends JPanel {

    public AClass(){this.aMethod();}
    private void aMethod(){}
}

...on Java class created?

EDIT : I try to invoke template code generation on new java source file created (see image)

enter image description here

I tried to edit the preferences -> Java -> code templates constructor body (see image) but I am not sure how to insert method invoke into constructor body :(

enter image description here

I tried to input this.aMethod(); into the edit text area but this doesn't generate constructor body as : public AClass(){this.aMethod();}

Community
  • 1
  • 1
user390525
  • 263
  • 1
  • 2
  • 18

1 Answers1

0

for question A :

You can edit template through eclipse preferences :

Java code style > Code template 

For question B :

You would have to create a custom new file wizard (a little overkill maybe...) you can find a simple tutorial on vogella : http://www.vogella.com/tutorials/EclipseWizards/article.html

flafoux
  • 2,080
  • 1
  • 12
  • 13
  • what kind of template should I create in the particularly described example? I mean method which constructor invokes ? – user390525 Apr 13 '15 at 09:59
  • After being familiar with custom wizard, you should take a look at eclipse internal code. Wizard called when creating a new class is : org.eclipse.jdt.ui.wizards.NewClassWizardPage I said overkill because it's a little complex for the purpose... – flafoux Apr 13 '15 at 10:09
  • concerning the source code I am not about to modify it right now I just ask is it possible to modify constructor body using template's variables or similar? I tried to edit the "Constructor body" with "java -> code templates" but it seems doesn't do the thing or I am just doing this wrong way? – user390525 Apr 13 '15 at 11:46
  • You simply add in the popup you posted, the hardcoded method name. Then when using generating constructor (`ctrl+space` in class body or `right clic > source > generate constructor using fields`) – flafoux Apr 13 '15 at 12:38
  • I tried to enter "this.aMethod();" into the edit template text area but that gives no generation result for constructor body on new java class created :( – user390525 Apr 14 '15 at 03:33
  • I don't get how to write template for the case I describe; Please give more details – user390525 Jul 08 '15 at 20:10