简体   繁体   English

Eclipse三元运算符快捷方式?

[英]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). 在Eclipse(3.4+以上)中,我正在搜索将if {} else {}条件块转换为java三元运算符 (或?:运算符)的快捷方式。

How can I do this? 我怎样才能做到这一点?

Excuse me if this is not relevant anymore. 如果这不再相关,请原谅。

I have written an eclipse plug-in that does exactly this: 我写了一个eclipse插件,它正是这样做的:

http://marketplace.eclipse.org/content/spartan-refactoring 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 编辑 :其他开发人员的重写版本可在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. 也就是说, Ctrl + Shift + L将列出所有 Eclipse快捷方式。

Related questions 相关问题

Well, you could add a Template to Eclipse like this: 好吧,您可以像这样向Eclipse添加一个模板:

${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. 将它命名为tern ,您可以为它自动创建三元运算符。

(Not sure if this is what you want) (不确定这是不是你想要的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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