Automatic repeated java text entry using Eclipse

Tony :

I am using Eclipse with Java. I need to define several very similar classes. It gets tedious typing the same thing automatically each time and wondering whether I could set up a short cut. I read Eclipse key bindings but it looks like something must already be in a plugin. This is what I need to type each time

 public class SomeClass extends Token {

     WebDriver driver = null;
     WindowStack stack = null;

     @Override 
     public void init() throw InitException {
           super.init();
           driver = TestCont.getWebDriver(); // defined and set elsewhere 
           stack = TestCont.getWindowStack();
     }

     @Override
     public void exec throws ExecException {

     }
 }

SomeClass is actually some unique name.

I guess I could just keep the text in a file and copy/paste, but it would be nice to create a short cut. I recently saw an online class where someone was using an IDE (I don't know which one it was). He typed psvm and it automatically changed to

 public static void main(String[] argc) {
 }

and doing something like new SomeClass(parm1, parm2, parm3).var automatically set to

 SomeClass var = new SomeClass(parm1, parm2, parm3);

and similarly anything with ".var" at the end would make such a variable. So I am wondering whether there is a way to do something similar (as above) in Eclipse with Java.

Not sure whether it matters but I have

Eclipse IDE for Enterprise Java Developers.
Version: 2018-12 (4.10.0)
Build id: 20181214-0600
OS: Windows 10, v.10.0, x86_64 / win32
Java version: 1.8.0_144
kutschkem :

You can define templates in Preferences -> Java -> Editor -> Templates

The content assist takes these into account for template completion (the name of the template).

For example, two of the predefined templates are called sysout and syserr. If you type sys, then trigger code completion, it suggests these two templates. Selecting sysout results in this code being inserted:

System.out.println();

(the template also defines places where other stuff needs to be inserted, where the cursor goes etc. but for your problem that seems like nice-to-have).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=144802&siteId=1