Introduce Variable refactoring: not supported in current context?

I could swear that I used to be able to select a piece of a String and do an Introduce Variable and have it do the right thing, e.g., before:
 
 
]]>Then do CtrlAltV and it does this:
 
 
 
Which is kind of funny because it's showing what I want (the + "now" +), but then when I hit OK, it's undone. :-(
 
Is this a bug, or a feature request? :-)
 
;ted
]]>



Attachment(s):
IntroduceVariableInStringNotWorking.png
IntroduceVariableInString.png
3 comments
Comment actions Permalink

Hello Ted,

This feature is provided by the SmartIntroduce plugin.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hello Ted,

Which is kind of funny because it's showing what I want (the + "now" +),
but then when I hit OK, it's undone. :(


Well, this is because you cannot extract a variable in the context you're in, which seems to be a
field-declaration. Pressing Ctrl-Alt-F, -C or -M to introduce another Field, Constant or even a
Method would work though.

The funny part, which breaks the string into "..." + "now" and then reverts it happens because the
SmartIntroduce plugin doesn't check whether the action is legal at the current place and leaves this
decision up to IDEA. When the refactoring isn't possible or is canceled by the user, the change is
reverted again.

Sascha

0
Comment actions Permalink

Hi Sascha,

Thanks for the reply... You're right, I didn't even realize that I was
outside of the method when I was trying to extract a variable, so user
error. :)

Is there any way to make the error message a little more informative? Not a
big deal, but if it said "Introduce Variable refactoring is not supported
here because you're not inside of a method" it would have prevented me from
embarrassing myself.

;ted

"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:fofc1c$i9g$1@is.intellij.net...

Hello Ted,

>
>> Which is kind of funny because it's showing what I want (the + "now" +),
>> but then when I hit OK, it's undone. :(
>

Well, this is because you cannot extract a variable in the context
you're in, which seems to be a field-declaration. Pressing Ctrl-Alt-F, -C
or -M to introduce another Field, Constant or even a Method would work
though.

>

The funny part, which breaks the string into "..." + "now" and then
reverts it happens because the SmartIntroduce plugin doesn't check whether
the action is legal at the current place and leaves this decision up to
IDEA. When the refactoring isn't possible or is canceled by the user, the
change is reverted again.

>

Sascha



0

Please sign in to leave a comment.