开发者

How to convert a rvalue into assignment in IntelliJ IDEA?

Let there is an existing code:

foo().bar();

How IDEA could help me to convert that into the following assignment statement?

List<SomeClass>开发者_如何转开发 lvalue = foo().bar();

I looked at Live Templates but have found nothing about this case although personally I'd use such a template frequently.


Select the expression and perform Refactor -> Introduce Variable. e.g. <ctrl>+<alt>+V

One of things I like about IntelliJ is that allows refactoring of incomplete code. I use it to write code all the time. (every third line)

Note: If there is more than one occurrence of the expression it will give you the option to replace them all.

You can also extract a section of a String e.g.

String text = "one two three";
String text2= "to two too";

I select the word two and do <ctrl>+<alt>+V, select replace all and I have.

String two = "two";
String text = "one " + two + " three";
String text2= "to " + two + " too";

This is more useful for extracting a constant, or a parameter. (allows you to parametrize part of a string)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜