2

So if I declare a private member such as

private MyObject test;

I want to create a template that will generate code in the following format

public MyObject retrieveAllMyObjects() {
    return test.findAll();
}

I have been messing around with the templates but I can't even figure out how to activate the templates. when I do the Ctrl+Space i just get no template proposals message

public ${return_type} retrieveAll${field}s() {

}

Obviously this is just a starting point, i was just trying to see if i could get eclipse to generate this and then I would go from there, but no such luck. My template doesn't show up anywhere. The context im using is "Java Type Members" what am I doing wrong??

Raymond Holguin
  • 1,050
  • 2
  • 12
  • 35

1 Answers1

1

Maybe you are happy with this solution:

private ${type} ${name};

public ${type} retrieveAll${type}s() {
    return  ${name}.findAll();
}

How to use it:

  1. Set up a code template with name 'retrieveAll'
  2. Go to your class
  3. type 'ret'
  4. hit <ctrl>+<space>
  5. select retrieveAll
  6. <Enter>
  7. type your desired Type, e.g. String
  8. <Tab>
  9. type your desired field name, e.g. test
  10. <Enter>
Absurd-Mind
  • 7,884
  • 5
  • 35
  • 47
  • Thanks your code worked but i was only able to get the code template to work only if i edited one of the existing templates in the system to use my code. I took the "private_static_method" stock template and put the code in and it worked. but if I create a new template with the same exact configuration it does not appear. do you know if you have to do something special to get new templates to register in eclipse so they can be used? – Raymond Holguin Aug 13 '12 at 16:13