views:

255

answers:

1

By default, eclipse generates getters/setters according to JavaBeans regular properties style:

* public void setName(String name)
* public String getName()

As of J2SE 5.0 JavaBeans specification allows IndexedPropertyChangeEvents which have a different getter/setter naming scheme for arrays:

* public void setName(int index, String name)
* public String getName(int index)
* public void setName(String[] names)
* public String[] getName()

How can you configure eclipse to generate getters and setters which follow this style?

+2  A: 

If there was a simple option for it, it would be in the Windows->Preferences->Java->Code Style. This is where the setting for telling the generator to use "is" for the getter on boolean variables. You'd probably have to write a plug-in or alter the code generation mechanism.

As an alternative you can do them when you need them, with a template. Something along the lines of:

public void set${l:List} (int i, String s)
{
  ${l}.set(i, s);
}

public String get${l:List} (int i)
{
  return ${l}.get(i);
}

And if not, there is always search and replace http://dev.eclipse.org/newslists/news.eclipse.tools.jdt/msg13332.html

David Newcomb