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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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.