简体   繁体   English

Eclipse:Java的全文自动完成?

[英]Eclipse: Fulltext autocompletion for Java?

can I has fulltext autocompletion for Java @ Eclipse? 我可以为Java @ Eclipse启用全文自动填充吗? Let's demonstrate: 让我们演示一下:

Final piece of code: 最后一段代码:

getVariants().add(new Variant(MediaType.TEXT_XML));

How do I code now: 我现在该如何编码:

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter]. getv [ctrl + space] .a [Enter]新V [ctrl + space,向下箭头,输入] M [Ctrl + Space,Enter]。 text_x text_x

Basically, Eclipse completes word "TEXT_XML" when I provide letters "TEXT_X". 基本上,当我提供字母“ TEXT_X”时,Eclipse将完成单词“ TEXT_XML”。

How would I like to code: 我想如何编码:

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter]. getv [ctrl + space] .a [Enter]新V [ctrl + space,向下箭头,输入] M [Ctrl + Space,Enter]。 xml XML文件

and Eclipse should realise I meant "TEXT_XML" (fulltext autocompletion). Eclipse应该意识到我的意思是“ TEXT_XML”(全文自动完成)。

As far as I'm aware, there is no way of enabling a full-text code completion in the Eclipse preferences view . 据我所知, 还没有办法在Eclipse preferences视图中启用全文代码完成 This has been bugging me for a while, too. 这也困扰了我一段时间。 I did quite a bit of digging and I'm pretty certain there is no easy way of achieving this. 我做了很多挖掘工作,并且我确定没有简单的方法可以实现这一目标。

However, there are two ways of implementing the desired, but I assume both of which are way to much work for fixing this little nuisance. 但是,有两种方法可以实现所需的目标,但是我认为这两种方法都是解决这一小麻烦的工作。

  1. There is an Eclipse plug-in extension point for the JDT Java Completion Proposal Computer - reference page A sample project which implements this extension point can be found in this repository . JDT Java完成提议计算机参考页中有一个Eclipse插件扩展点。可以在此存储库中找到实现此扩展点的示例项目。 This is fairly convenient, but still a lot of boilerplate and tedious coding. 这相当方便, 但是仍然有很多样板代码和乏味的代码。

  2. You can change the findKeywords method in the internal org.eclipse.jdt.internal.codeassist.CompletionEngine class and compile your own JDT fork. 您可以在内部org.eclipse.jdt.internal.codeassist.CompletionEngine类中更改findKeywords方法,并编译自己的JDT fork。 But this is discouraged for so many reasons. 但是,出于多种原因,我们不建议这样做。 First of all, this class is a 12000 line monster and hard to just jump in. And of course, if you'd only hack a kludge in, there is little chance of this becoming an official contribution, so you'd need to worry about every eclipse release. 首先,该类是12000线怪兽,很难跳进去。当然,如果您只想闯入一团,这几乎不可能成为官方贡献,因此您需要担心关于每个月食发布。

Additionally, there might be a very chillaxed way in the future. 另外,将来可能会有一个非常冷淡的方式。 Although this might exceed your requirements a bit. 尽管这可能会超出您的要求。

Have a look at the Code Recommenders project . 看一下Code Recommenders项目 This blog has an outline of the project objectives It doesn't mention full-text auto-completion specifically, but I'd assume its matching algorithms go even beyond that. 博客 概述了项目目标。它没有特别提到全文自动完成功能,但是我认为它的匹配算法甚至超出了该范围。

Edit : In the proper SO-spirit, I'll keep this answer up to date: 编辑 :在适当的SO精神中,我将使此答案保持最新:

Apparently the feature is now implemented in the Code Recommenders plug-in. 显然,该功能已在“代码推荐器”插件中实现。 See this blog post and this forum thread . 请参阅此博客文章和此论坛主题 I'm quite surprised it only took 10 locs. 我很惊讶它只用了10个位置。 To me the extension point appeared more complex. 对我来说,扩展点显得更加复杂。

If your MediaType class does not contain a large number of accessible fields/methods you could simply use 如果您的MediaType类不包含大量可访问的字段/方法,则可以简单地使用

getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter].[Ctrl+Space, down arrow, Enter]

you may need to press the down arrow more than once, though to select the desired field. 您可能需要多次按下向下箭头,才能选择所需的字段。

Yes, you can using Templates. 是的,您可以使用模板。 (Window -> Preferences -> Java -> Editor -> Templates) (窗口->首选项-> Java->编辑器->模板)

The basic usage is you set the name to what you want to type and you set the pattern to what you want to appear. 基本用法是将名称设置为要键入的名称,并将模式设置为要显示的名称。

In my testing I set the name to xml , the Context to Java , the Pattern to TEXT_XML and Automatically insert turned on. 在测试中,我将名称设置为xml ,将上下文设置为Java ,将模式设置为TEXT_XML并打开了自动插入功能。 Then when I typed out your example I was able to follow a pattern like... 然后,当我输入您的示例时,我可以遵循以下模式:

getv[ctrl+space].a[enter]new V[ctrl+space, down arrow, Enter]M[ctrl+Space, Enter].xml[ctrl+space]

and since Automatically insert was turned on poof TEXT_XML was inserted. 既然自动插入被打开 TEXT_XML插入。

Templates have much more functionality than that and the one source I used for this answer was Effective Eclipse . 模板的功能远不止这些,而我用于此答案的一个来源是有效的Eclipse

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM