can not extract method or variable 1 + "string"

I was having problems extracting metfod (see below) but after some tinkering
realized that expression like 1 + "text" can not be extracted as method or
variable


==========
I might be missing something but I cant extract neither method or variable
from following expression

System.out.println("TOTAL TIME = " + ((System.currentTimeMillis() - t1) /
1000) +
" mem = " + (Runtime.getRuntime().freeMemory() /1000)
+ " / " + (Runtime.getRuntime().totalMemory() / 1000));


I am trying to extract:
" mem = " + (Runtime.getRuntime().freeMemory() /1000) + " / " +
(Runtime.getRuntime().totalMemory() / 1000)

selected block should represent set of statements or expression



7 comments
Comment actions Permalink

You can only extract portions of an expression if they form an expression themselves. With string concatenation, this would mean you could extract concatenations from the beginning or middle, but not the end. It has to do with the associativity of the "+" operator. Yes, it's very jarring. There are any number of feature requests for being able to extract from the middle or end of a concatenation, or you can use the SmartIntroduce plugin, which does just that (as well as a bunch of other stuff).

--Dave Griffith

0
Comment actions Permalink

Yes, that's true. Idea cannot make virtual modifications to PSI. One could
of course use brutal force to parenthesize the selection, but I'm not sure
we want to go this way.
BTW, does anyone know what does SmartIntroduce perform to make it work?
Eugene.

"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:30762185.1112754188134.JavaMail.itn@is.intellij.net...

You can only extract portions of an expression if they form an expression

themselves. With string concatenation, this would mean you could extract
concatenations from the beginning or middle, but not the end. It has to do
with the associativity of the "+" operator. Yes, it's very jarring. There
are any number of feature requests for being able to extract from the middle
or end of a concatenation, or you can use the SmartIntroduce plugin, which
does just that (as well as a bunch of other stuff).
>

--Dave Griffith



0
Comment actions Permalink

I'm pretty sure it does brute force parenthesization, does that extraction, and then removes the parentheses.

--Dave Griffith

0
Comment actions Permalink

Dave Griffith wrote:

I'm pretty sure it does brute force parenthesization, does that extraction, and then removes the parentheses.


Correct, that's how it works. The good part is that IDEA removes the inserted parentheses automatically ;)

Sascha

0
Comment actions Permalink

The bad part is probably that it does not remove them if the user cancels
refactoring...
Eugene.

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

Dave Griffith wrote:

I'm pretty sure it does brute force parenthesization, does that

extraction, and then removes the parentheses.
>

Correct, that's how it works. The good part is that IDEA removes the

inserted parentheses automatically ;)
>

Sascha



0
Comment actions Permalink

Eugene Vigdorchik (JetBrains) wrote:

The bad part is probably that it does not remove them if the user cancels
refactoring...
Eugene.


Hmm, is that just a guess or did you experience that yourself? I'm asking
because this has been taken care of and should not happen. I'd be curious
to know under what conditions it happens, if it does.

Sascha

0
Comment actions Permalink

Sascha,
no it was just a guess.
Sorry for false alarm.
Eugene.

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

Eugene Vigdorchik (JetBrains) wrote:

The bad part is probably that it does not remove them if the user

cancels

refactoring...
Eugene.

>

Hmm, is that just a guess or did you experience that yourself? I'm asking
because this has been taken care of and should not happen. I'd be curious
to know under what conditions it happens, if it does.

>

Sascha



0

Please sign in to leave a comment.