不带花括号的 if 语句的 Eclipse 缩进

发布于 2024-11-19 05:04:42 字数 429 浏览 4 评论 0原文

当使用不带大括号的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2024-11-26 05:04:42

我给出了 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 WindowPreference

Choose JavaCode StyleFormatter

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.

稍尽春風 2024-11-26 05:04:42

只需添加大括号,这是很好的编码习惯!

或者在以下情况下使用三元:

$current_class = ($i === $this->get_current_page()) ? "class='current'" : "");

Just add the braces, it's good coding practice!

Or use the ternary if:

$current_class = ($i === $this->get_current_page()) ? "class='current'" : "");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文