File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse Setters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Reply Bookmark "Eclipse Setters" Watch "Eclipse Setters" New topic
Author

Eclipse Setters

Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Howdo.
If I define a field in a class in Eclipse as
public String fooBar;
then generate the setter
I get
public void setFooBar(String string){
fooBar = string;
}
I'd like to configure it so that the generated method signature has a more meaningfull input parameter.
i.e public void setFooBar(String fooBar){
this.fooBar = fooBar;
}
or even public void setFooBar(String _fooBar){
this.fooBar = _fooBar;
or fooBar = _fooBar;
}
Is this possible?
TIA Graham
Dave Hewy
Ranch Hand

Joined: Aug 21, 2003
Posts: 93
Hello Mr VMead - we meet again !
I'm not sure which version of Eclipse you're using, but I'm using the latest stable beta of V3 - V3M4.
When I do as you suggest, I get...


Note, that I have set my params to be prepended with "p"
Which version are you using?
Dave
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
2.1.x does it sometimes.
It's not consistent though, sometimes it does as you describe from 3.0 as well, haven't yet discovered what causes it to sometimes use a form of the parameter type as the parameter name.


42
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
In 2.1.x I've noticed that if you have a method call written prior to generating the method, then it uses the name of the parameter passed to the method. I've been looking for a setting that would allow it to parse the method name to get the variable name, but I haven't found one yet.


Matthew Phillips
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Matthew: Tried to create a method that used the getter prior to generating the method, but still got the good old foo = string;
Mr Hewy: I'm using 2.1.1 and if I use the prefix setting that you do I get the result
/**
* @param pString
*/
public void setMyparm(String pString) {
myparm = pString;
}
Reckon its maybe a version thing, I'll download 3 and see what happens
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Had a butchers on the Eclipse.org newsgroups, it appears that
Version 2.0.x used
public void setFoo(String foo){
this.foo = foo;
}
Version 2.1.X
public void setFoo(String string){
foo = string;
}
The guys at Eclipse then obviously relised this was cobblers so
Version 3.0 reverts back to the 2.0 way of doing it.
Mr Hewy: They recommend not prefixing the parms coz this inflates the Javadoc but there you go.
BTW there is no way of altering the 2.1 behaviour either.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Originally posted by Graham VMead:
Matthew: Tried to create a method that used the getter prior to generating the method, but still got the good old foo = string;

I went back and tested what I did. Instead of creating the method through Source > Generate Getter/Setter, I use the quick fix to generate the method from the code I wrote to call the method. That gives it the proper local variable name, but it doesn't generate the this.field = field line in the setter method.
 
 
subject: Eclipse Setters
 
Threads others viewed
[Easy] Shift String
DataAccessFactory Dilemma
Interface assignments
Help me please! Constructor Calls Overridable Method
JSP / Bean prob.
IntelliJ Java IDE