不带花括号的 if 语句的 Eclipse 缩进
当使用不带大括号的 if-statements
时,Eclipse 不会缩进它们,如下所示:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
但我确实想缩进它们,如下所示:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
我正在使用 CTRL + Shift + F 来缩进代码。
顺便说一句,我正在使用 Eclipse 进行 PHP 开发。
When using if-statements
without curly braces, Eclipse don't indent them such as below:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
But I do want to indent them like below:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
I am using CTRL + Shift + F to indent the code.
By the way I am using Eclipse for PHP development.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我给出了 Java 的答案,但我希望用“PHP”替换“Java”也应该有效:
转到窗口→首选项
选择Java → 代码样式 → 格式化程序
编辑格式并查找需要更改的内容(缩进或其他内容)。
保存(如果您想保留,请导出)
现在
CTRL+SHIFT+F
将按照您想要的方式缩进代码。I give my answer for Java, but I excpect that replacing "Java" by "PHP" should work as well:
Go to Window → Preference
Choose Java → Code Style → Formatter
Edit the format and look for whatever you need to change (indent or other things).
Save (export if you want to keep it)
Now
CTRL+SHIFT+F
will indent the code the way you wanted.只需添加大括号,这是很好的编码习惯!
或者在以下情况下使用三元:
Just add the braces, it's good coding practice!
Or use the ternary if: