| Summary: | [getter setter] A bit more intelligence for "Generate getter/setter generate methods" | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Victor Toni <victor.toni> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | RESOLVED WORKSFORME | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | manaster, martinae |
| Version: | 3.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
You can add you null check to the getter body template. In general it is difficult to find something that makes sense everywhere and that helps all user. I think even with more smartness, you would have to look at the generated code. And you would probably make as many changes as you would have done without any smartness from the getter/setter wizard. -> We don't plan to do more in that area. *** Bug 214675 has been marked as a duplicate of this bug. *** |
Generating getter/setter methods works fine for the trival case but often additional actions may be a bit more useful e.g. returning unmodifiable collections or checking for null parameters. Collections may be a corner case but checking for null parameters will be a regular task. ---------------------------------------------- import java.util.ArrayList; import java.util.Collections; import java.util.List; public class TestGetterSetter { private static final List _list = new ArrayList(); private String _name; public TestGetterSetter(final String name) { setName(name); } public List getList() { return Collections.unmodifiableList(_list); } public void setName(final String name) { if (null == name) { throw new NullPointerException("Name may not be null!"); } _name = name; } public String getName() { return _name; } }