如何从新类的末尾删除空行 - Eclipse [英] How to remove empty line from the end of new class - Eclipse

查看:194
本文介绍了如何从新类的末尾删除空行 - Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Eclipse Juno 4.2上工作(但问题与eclipse的旧版本相关),我发现一个令人烦恼的问题。当我们尝试使用默认格式化程序设置创建新类时,eclipse在文件末尾放一个空行。





我试图弄清楚自己如何删除这个烦人的行,并搜索格式化程序选项。我找到了可以帮助解决我的问题的选项,但我发现它默认是禁用。



解决方案

这不是一个空行。它只是在Eclipse中出现。



当您在Eclipse中看到空行时,表示文件的最后一行以新的行字符终止。也就是说,Java文件中的最后一个字符可能是} \\\
(在* nix上,带有LF行结尾)或} \r \\\
(Windows上的CRLF行结尾),每个案例都在文件的末尾。



您可以向自己证明这一点在* nix上使用 tail cat 。如果提示出现在与最后一行代码相同的行上,则没有尾随的新行。如果提示出现在单独的行上,则会出现一个尾随的新行字符。如果在提示之前有空行,那么文件中有空行。



如果上述不能说服你,请使用十六进制编辑器。 :o)空行将显示为两个连续的行结尾: \\\
\\\
\r\\\
\r\\ \\ n
(分别在* nix和windows上)。



文件的最后一行没有错误,在结束。事实上,这是一个好主意,将其留在那里,因为一些工具会警告,如果它不在那里。这些工具包括 Checkstyle (有一个 Eclipse Checkstyle插件)和 diff



Eclipse允许您将光标放在这里,以防您想在文件末尾添加新内容。 (这在Java中经常不需要,因为大多数人不会在文件中放置多个顶级类型。)



最好只是把它留在那里,并用于Eclipse显示。


I currently work on Eclipse Juno 4.2 (but problem is connected with older versions of eclipse as well) and I found an irritating issue. When we try to create new class with a default formatter settings, eclipse put an empty line at the end of file.

I tried to figure out by myself how to remove this annoying line and search in formatter options. I found option that could help solve my problem but i found it's disable by default.

My question is: How to get rid of this line?

解决方案

It's not really an empty line. It just appears that way in Eclipse.

When you see the blank line in Eclipse, it means that the last line of the file is terminated by a new line character. That is, the last characters in your Java file are probably }\n (on *nix, with LF line endings) or }\r\n (CRLF line endings on Windows), followed in each case by the end of the file.

You can prove this to yourself using tail or cat on *nix. If the prompt appears on the same line as the last line of code, then there's no trailing new line. If the prompt appears on a separate line, then there is a trailing new line character. If there's a blank line before the prompt, then there's an empty line in the file.

If the above doesn't convince you, use a hex editor. :o) An empty line would appear as two consecutive line endings: \n\n or \r\n\r\n (on *nix and windows respectively).

There's nothing wrong with the last line of your file having a new line character at the end. In fact, it's a good idea to leave it there, because some tools will warn if it's not there. These tools include Checkstyle (there's an Eclipse Checkstyle plugin) and diff.

Eclipse allows you to put the cursor there in case you want to add new content to the end of the file. (This isn't often needed in Java, because most people don't put more than one top-level type in a file.)

Best just to leave it there, and get used to Eclipse showing it.

这篇关于如何从新类的末尾删除空行 - Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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