Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Modifying setter generation?
Modifying setter generation? [message #205428] Wed, 01 June 2005 15:11 Go to next message
Eclipse UserFriend
I'd like to add the keyword "final" before the argument in the setter
signature. Is there any way to modify the template to do this?

I see you can check off "final" but that's for the whole method. I want it
to look like this:

public void setFoo(final int foo) {
...
}

Otherwise, CheckStyle warns about the variable needing to be final.


Thanks,
Sean LeBlanc
Re: Modifying setter generation? [message #205510 is a reply to message #205428] Thu, 02 June 2005 05:49 Go to previous messageGo to next message
Eclipse UserFriend
This cannot be specified in the template. There is however a feature request
to introduce a final code generation setting

Cheers

Tobias

"Sean LeBlanc" <seanleblanc@comcast.net> wrote in message
news:d7l1ja$71m$1@news.eclipse.org...
> I'd like to add the keyword "final" before the argument in the setter
> signature. Is there any way to modify the template to do this?
>
> I see you can check off "final" but that's for the whole method. I want it
> to look like this:
>
> public void setFoo(final int foo) {
> ...
> }
>
> Otherwise, CheckStyle warns about the variable needing to be final.
>
>
> Thanks,
> Sean LeBlanc
>
Re: Modifying setter generation? [message #205587 is a reply to message #205510] Thu, 02 June 2005 10:19 Go to previous messageGo to next message
Eclipse UserFriend
"Tobias Widmer" <tobias_widmer@ch.ibm.com> wrote in message
news:d7mknr$vf3$1@news.eclipse.org...
> This cannot be specified in the template. There is however a feature
> request to introduce a final code generation setting

<snip>

Okay, thanks. I should have searched bugzilla first. I think this is what
you were referring to?

https://bugs.eclipse.org/bugs/show_bug.cgi?id=40078
Re: Modifying setter generation? [message #205613 is a reply to message #205428] Thu, 02 June 2005 14:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Sean LeBlanc wrote:
> I'd like to add the keyword "final" before the argument in the setter
> signature. Is there any way to modify the template to do this?
>
> I see you can check off "final" but that's for the whole method. I want it
> to look like this:
>
> public void setFoo(final int foo) {
> ...
> }
>
> Otherwise, CheckStyle warns about the variable needing to be final.

Does it really? That is simply not true. There is no inherent *need* for
setter arguments to be final. In fact, the only reason I know of to make
a method parameter final is when it is used in the code of a local inner
class.
Seems to me CheckStyle is being too stringent in this case.

Eric
Re: Modifying setter generation? [message #205814 is a reply to message #205587] Fri, 03 June 2005 12:25 Go to previous messageGo to next message
Eclipse UserFriend
Yes, there is also this one: bug 71748

"Sean LeBlanc" <seanleblanc@comcast.net> wrote in message
news:d7n4i5$m6a$1@news.eclipse.org...
>
> "Tobias Widmer" <tobias_widmer@ch.ibm.com> wrote in message
> news:d7mknr$vf3$1@news.eclipse.org...
>> This cannot be specified in the template. There is however a feature
>> request to introduce a final code generation setting
>
> <snip>
>
> Okay, thanks. I should have searched bugzilla first. I think this is what
> you were referring to?
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=40078
>
>
>
>
>
Re: Modifying setter generation? [message #205821 is a reply to message #205613] Fri, 03 June 2005 12:27 Go to previous messageGo to next message
Eclipse UserFriend
This can be configured. Some people just like to express the value semantics
of method argument by using the final keyword.

Tobias

"Eric Rizzo" <eclipse@rizzoweb.com> wrote in message
news:d7nhpj$beo$1@news.eclipse.org...
> Sean LeBlanc wrote:
>> I'd like to add the keyword "final" before the argument in the setter
>> signature. Is there any way to modify the template to do this?
>>
>> I see you can check off "final" but that's for the whole method. I want
>> it to look like this:
>>
>> public void setFoo(final int foo) {
>> ...
>> }
>>
>> Otherwise, CheckStyle warns about the variable needing to be final.
>
> Does it really? That is simply not true. There is no inherent *need* for
> setter arguments to be final. In fact, the only reason I know of to make a
> method parameter final is when it is used in the code of a local inner
> class.
> Seems to me CheckStyle is being too stringent in this case.
>
> Eric
Re: Modifying setter generation? [message #206861 is a reply to message #205613] Thu, 16 June 2005 10:55 Go to previous message
Eclipse UserFriend
"Eric Rizzo" <eclipse@rizzoweb.com> wrote in message
news:d7nhpj$beo$1@news.eclipse.org...
> Sean LeBlanc wrote:
>> I'd like to add the keyword "final" before the argument in the setter
>> signature. Is there any way to modify the template to do this?
>>
>> I see you can check off "final" but that's for the whole method. I want
>> it to look like this:
>>
>> public void setFoo(final int foo) {
>> ...
>> }
>>
>> Otherwise, CheckStyle warns about the variable needing to be final.
>
> Does it really? That is simply not true. There is no inherent *need* for
> setter arguments to be final. In fact, the only reason I know of to make a
> method parameter final is when it is used in the code of a local inner
> class.
> Seems to me CheckStyle is being too stringent in this case.
>
> Eric

As Tobias points out, CheckStyle can be configured to ignore this.

However, I like to have this check left on. This is something that is
recommended in _Hardcore Java_, as well, and I think in many cases it makes
sense as a guard against unintended consequences.
Previous Topic:Keybindings lost
Next Topic:Annoying problem with debugger, 3.1RC1, Java 1.5
Goto Forum:
  


Current Time: Tue Jul 15 17:07:03 EDT 2025

Powered by FUDForum. Page generated in 0.10865 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top