6

In Java Code Style -> Code Templates there is a "Delegate Methods" option under comments but not under code. I tried changing the "Setter body" template because I wanted to automatically create a bunch of delegated setter methods. However, it didn't work for delegates.

So can I add a Delegate Methods entry to the code part of Code Templates or do I need to do something else?

I am using Eclipse Indigo on Win 7.

jnash67
  • 271
  • 2
  • 7

2 Answers2

0

To create getter and setter methods, select the field's declaration and invoke Source -> Generate Getter and Setter.

If you use a name prefix or suffix be sure to specify this in the Code Style preference page (Window > Preferences > Java > Code Style).

Another way to create getters and setters is using content assist. Set the cursor in the type body between members and press Ctrl+Space to get the proposals that create a getter or setter method stub.

josdios
  • 21
  • 4
  • i know how to generate getter/setter- talking about custom- made delegate methods... – Franz Ebner Jul 09 '12 at 09:40
  • In that case, you must create your own template which fits your requirements. Here you have a good begining point: http://eclipse.dzone.com/news/visual-guide-templates-eclipse – josdios Jul 09 '12 at 09:51
  • what I want to accomplish exactly is that i can generate a method such as foomapPut(Object k, Object v){...} and not put(Object k, Object v){...} ... – Franz Ebner Jul 09 '12 at 10:17
  • There is no way to fully automated what you want, because `${name}` works well in the context of a method, but does not work with text like `${name}Put(...)` and in context of class. You must use `${text}` instead, and add manually the desired name (e.g. _foomap_) – josdios Jul 09 '12 at 10:48
  • 2
    _there is no way_ with templates. perhaps you could do a kind of refactoring participant, that implements this functionallity – josdios Jul 09 '12 at 10:52
0

You can do that but you need to develop a plugin using eclipse's refactoring API provided by the Java Development Tools (JDT) as follows:

Anyone who supports a programming language in an Eclipse-based IDE will be  
asked sooner or later to offer automated refactorings - similar to what is  
provided by the Java Development Tools (JDT). Since the release of Eclipse 3.1, 
at least part of this task (which is by no means simple) is supported by a 
language neutral API:the Language Toolkit (LTK). But how is this API used?

Look at this one for a start.

Community
  • 1
  • 1
GingerHead
  • 8,130
  • 15
  • 59
  • 93