Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 85784

Summary: [getter setter] A bit more intelligence for "Generate getter/setter generate methods"
Product: [Eclipse Project] JDT Reporter: Victor Toni <victor.toni>
Component: UIAssignee: 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:

Description Victor Toni CLA 2005-02-17 21:21:40 EST
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;
	}
}
Comment 1 Martin Aeschlimann CLA 2005-02-18 09:00:47 EST
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.
Comment 2 Dani Megert CLA 2008-01-09 02:14:11 EST
*** Bug 214675 has been marked as a duplicate of this bug. ***