Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Refactoring warning instead of appending this
Refactoring warning instead of appending this [message #147577] Fri, 05 March 2004 22:32 Go to next message
Eclipse UserFriend
Originally posted by: igor.noemail.com

Hi,

I had a problem upon refactoring in this code:

class MyClass {
private int i;
MyClass(int j) {
i = j;
}
}

Renaming i into j displays a warning instead of creating

class MyClass {
private int j;
MyClass(int j) {
this.j = j;
}
}

Why isn't "this.j" automatically created? IMHO this should be done.

Igor
Re: Refactoring warning instead of appending this [message #147585 is a reply to message #147577] Fri, 05 March 2004 23:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.cuthis.mit.edu.andthis

>Why isn't "this.j" automatically created? IMHO this should be done.

Igor,
there's *always* going to be cases for which someone will think they're
obvious and missing.
but the developers cannot read people's minds - that's why you should enter
a feature request
(it's JDT UI, btw)

cheers
a.
Re: Refactoring warning instead of appending this [message #147766 is a reply to message #147577] Mon, 08 March 2004 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-user.jibeinc.com

Igor Akkerman wrote:

> Hi,
>
> I had a problem upon refactoring in this code:
>
> class MyClass {
> private int i;
> MyClass(int j) {
> i = j;
> }
> }
>
> Renaming i into j displays a warning instead of creating
>
> class MyClass {
> private int j;
> MyClass(int j) {
> this.j = j;
> }
> }
>
> Why isn't "this.j" automatically created? IMHO this should be done.

I disagree. I think a warning is definitely appropriate. I guess if you
really are sure you want that, then it should go ahead and do it after
warning you, but I always try to avoid code where method arg names match
instance variable names exactly - it just makes it too easy to forget
the "this." somewhere and end up with a confusing bug.

Eric
--
Eric Rizzo
Software Architect
Jibe, Inc.
http://www.jibeinc.com
Re: Refactoring warning instead of appending this [message #147789 is a reply to message #147766] Mon, 08 March 2004 16:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: igor.noemail.com

Eric Rizzo <eclipse-user@jibeinc.com> wrote:

>Igor Akkerman wrote:
>
>> Hi,
>>
>> I had a problem upon refactoring in this code:
>>
>> class MyClass {
>> private int i;
>> MyClass(int j) {
>> i = j;
>> }
>> }
>>
>> Renaming i into j displays a warning instead of creating
>>
>> class MyClass {
>> private int j;
>> MyClass(int j) {
>> this.j = j;
>> }
>> }
>>
>> Why isn't "this.j" automatically created? IMHO this should be done.
>
>I disagree. I think a warning is definitely appropriate. I guess if you
>really are sure you want that, then it should go ahead and do it after
>warning you, but I always try to avoid code where method arg names match
>instance variable names exactly - it just makes it too easy to forget
>the "this." somewhere and end up with a confusing bug.

I agree that a warning is appropriate. But after warning me and after
I have accepted, it should definitely not produce the code it produces
now:
....
My Class(int j) {
j = j;
}
....
because this cannot be anything but an error.

You may call your method arguments differently, I would not like to do
this. By the way, AFAIK, it is a Java convention not to do so.

Igor
Re: Refactoring warning instead of appending this [message #147797 is a reply to message #147789] Mon, 08 March 2004 18:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.to.reply.remove.whats.unneeded.mit.edu

> My Class(int j) {
> j = j;
> }
> ...
> because this cannot be anything but an error.

and eclipse marks it as one if you set the compiler prefs appropriately!
a.
Re: Refactoring warning instead of appending this [message #147899 is a reply to message #147797] Tue, 09 March 2004 05:51 Go to previous message
Eclipse UserFriend
Originally posted by: igor.noemail.com

Adam Kiezun <akiezun@to.reply.remove.whats.unneeded.mit.edu> wrote:

>> My Class(int j) {
>> j = j;
>> }
>> ...
>> because this cannot be anything but an error.
>
>and eclipse marks it as one if you set the compiler prefs appropriately!

of course. And that's why the refactoring module should be aware of
not creating such code. Not even after a warning.

Igor
Previous Topic:Where should I look for the behavior you get for for templates
Next Topic:imports not recognized with source subdirectory
Goto Forum:
  


Current Time: Wed Jul 09 23:22:10 EDT 2025

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

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

Back to the top