简体   繁体   中英

Eclipse ternary operator shortcut?

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

How can I do this?

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM