开发者

Eclipse ternary operator shortcut?

In Eclipse (3.4+ upwards), I was searching for shortcut which converts the 开发者_JS百科if {} else {} condition block to the java ternary operator (or the ?: operator).

How can I do this?


There is no such shortcut. Refactoring statements into expressions isn't a trivial process, and isn't always possible to begin with. The process would be too complicated to be automated.

That said, Ctrl + Shift + L will list ALL Eclipse shortcuts.

Related questions

  • Hidden features of Eclipse
  • What is your favorite hot-key in Eclipse


Excuse me if this is not relevant anymore.

I have written an eclipse plug-in that does exactly this:

http://marketplace.eclipse.org/content/spartan-refactoring

Feel free to report back if you have problems with installation or using this plug-in.

Edit: Re-written version by other developers is available at https://marketplace.eclipse.org/content/spartan-refactoring-0


Well, you could add a Template to Eclipse like this:

${condition:field(boolean)}? ${positive:field(void)}: ${negative:field(void)};

Name it something like tern and you can have it auto-create the ternary operator for you.

(Not sure if this is what you want)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜