Eclipse:可以保存格式化代码吗? [英] Eclipse: Can you format code on save?

查看:174
本文介绍了Eclipse:可以保存格式化代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中, Windows - > 首选项 - > Java - > 代码样式,您可以定义用于注释和代码的代码模板,您可以设置代码格式化程序。

In Eclipse, under Windows -> Preference -> Java -> Code Style, you can define code templates for comments and code, and you can setup a code formatter.

我想知道在Eclipse中是否可能每次保存源文件时都会影响这些设置。基本上,我不希望突出显示所有内容,而是按 Ctrl + Shift + F ,我希望Eclipse负责确保我的代码格式正确

I'm wondering if it is possible in Eclipse to have these setting take affect every time I save a source file. Basically, instead of me highlighting everything and pressing Ctrl+Shift+F, I want Eclipse to be responsible for making sure my code is formatted properly.

这是可能的,您如何设置?

Is this possible and how do you set it up?

注意使用自动-Format:最好选择格式化编辑行,因为当重新格式化已经没有格式化的源代码控制的整个文件时,合并更改变得非常困难。

Note On Using the Auto-Format: It's probably best to choose "Format Edited Lines" as merging changes becomes very difficult when you reformat a whole file that is in source control already that was not formatted properly. Already did this to a co-worker.

推荐答案

首选项下,选择 Java - > 编辑器 - > 保存操作。检查在保存上执行所选的操作,并检查格式源代码框。

Under Preferences, choose Java --> Editor --> Save Actions. Check the Perform the selected actions on save, and check the Format source code box.

这可能或可能在以前的Eclipse版本中不可用。我知道它有效:

This may or may not be available in previous versions of Eclipse. I know it works in:

Version: 3.3.3.r33x_r20080129-_19UEl7Ezk_gXF1kouft<br>
Build id: M20080221-1800

这篇关于Eclipse:可以保存格式化代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆