使用Eclipse的单词拼写检查功能

        (原帖地址:http://www.javalobby.org/java/forums/t17453.html)

        (附:以下是帖子内容的主要几点

         1.在使用spelling功能时请导入词典库(txt文档, 每行一个单词). 如果需要素材, 可到Kevin's Word List on Sourceforge.net上获取.不过若是觉得在这上面寻找麻烦, 也可以使用作者上传的词库, 地址是here. 将该页面打开, 可以看到一行行词汇, 将他们全部复制保存到txt文档中, 然后在eclipse中导入就可以了. 你也可以添加自己的词汇.

        2.在使用过程中, eclipse会在拼写错误的单词下面显示红色的波浪线, 这时你只要按下<ctrl>+1就可以看到供选择的匹配项. 不过eclipse在最佳匹配这方面做得差强人意, 大伙就将就下吧.)

        原文如下:

        Ahh, spelling errors. I think we all make them - I know I do anyway. After typing these tips on a near daily basis I've begun to recognize that no matter how good you think you are at spelling, stupid mistakes show up, and a lot of times you get a bad spelling habit stuck in your head and continually put too many c's in necessary or something. I would be surprised if a spelling error didn't find its way in to this very tip, as I'm usually too lazy to put a lot of effort into spell checking these :).

Spelling errors in documentation can mean the difference between life and death. Really?! No... not really - but spelling is important. Bugs are opened in large frameworks when spelling and grammatical errors are in the documentation. Really, it happens! In addition, people immediately take you more seriously when you spend the time to ensure that your spelling is accurate. Finally, it is definitely possible that spelling errors can convey a different meaning than intended. (Deprecate and Depreciate anyone?)

Thankfully, Eclipse has a little hidden gem that makes quick work of spelling errors. The spelling support in Eclipse has actually been around for a while now (if I'm not mistaken, it was enabled in 3.0), and recently (3.1 M4) it was enabled in the properties file editor in addition to the already supported Java editor. So, how do you enable it?

Well, the first step is to find the preference for it. That's a relatively simple process as I already know, and I am going to tell you ;) - just go to Window->Preferences->Editors[+]->Text Editors[+]->Spelling and check Enable Spelling .

Oops, wait a minute... it has a section to provide a 'User defined dictionary'. Is this mandatory? What format does it need to be in? Do we have to type all the words by hand? This could take a while! For spell checking to work, it is currently mandatory for you to provide a dictionary. Thankfully it's not that hard to find a word-list Eclipse can use. Eclipse supports a fairly standard one-word-per-line format for the 'dictionary' file, so we just have to find one of those. The best branching off point for that is probably Kevin's Word List on Sourceforge.net . Seem too hard? Ok, fair enough. I've compiled my own word list off of an amalgum of lists (I honestly can't remember which ones, otherwise I would be sure to give credit where credit is due), and I have uploaded it here . Fair warning! This file is substantial in size - so substantial that I couldn't attach it to this message in the conventional Javalobby 'Attach File' way (around 1.5 megabytes).

Ok, so now let's enable our spell-checking. I like to drop the dictionary file in the folder with my Eclipse installation, and then reference it in the preferences, as seen here:

Then all you have to do is use it. Spell checking shows up in one of two ways - first as squiggly warnings in your documentation and strings, and second as a preemptive auto-complete for content assist (assuming you have enabled that option in the advanced section seen in the screenshot above). Here is what the spelling error marker looks like (and what happens when I press Ctrl+1 with my cursor adjacent to the error):

Here is what it looks like using the auto-complete feature (Ctrl+Space):

Unfortunately, spelling support still needs a little work in some areas; it is no panacea. So, what would I like to see in the future? For one thing, there is no way yet to control what elements are spell-checked, and which ones aren't. What I mean by that is whether javadocs, regular comments, string literals, and/or type/method/field names are spell-checked. Currently all documentation and string literals are checked, but that's it. Frankly, my string literals need checking less often than my types and fields and methods - and in my string literals, it is more often the spell-checker would be wrong. In addition, the algorithm used for finding words of a closest match doesn't always seem the most appropriate - when using the word-list for auto-complete, if I were to type 'spell' and then press Ctrl+Space, I would like 'spelling' come up in the list before 'spew' - since that is the main benefit of an auto-complete feature - completing the word!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值