如何获得内容辅助“ for循环”。 Eclipse中的任何地方? [英] How to get content assist for "for loop" anywhere in Eclipse?

查看:107
本文介绍了如何获得内容辅助“ for循环”。 Eclipse中的任何地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中,在这样的一行之后:

In Eclipse, after a line like this:

列表列表= new ArrayList();

List list = new ArrayList();

在下面键入 for,然后键入 ctrl-space(默认情况下),将带来几个有助于完成此 for循环的选项:

Typing "for" just beneath, and followed by "ctrl-space" (by default), will bring several options that can help completing this "for loop":

但是,如果声明变量 list的位置远离此处(例如,作为类字段),则可能无法从此上下文中直接推断出,或者声明了很多列表,那么该帮助无法正常工作:

But if the variable "list" is declared far from here (e.g. as a class field) which may not be directly inferred from this context, or there are many Lists declared,then the assistance doesn't work well:

@@分割线---

@@ split line ---

在某些情况下,Eclipse可以提供帮助,但不要不适用于成员变量。例如。手动键入另一个,并在:之后输入ENTER并不能说服Eclipse猜测它。...。

In some cases, Eclipse can assist, but just don't work for member variable. E.g. manually type "another" and ENTER after the ":" didn't persuade Eclipse to guess about it....

(PS适用情况:

自动猜测

输入想要的名称,然后按ENTER,效果很好

Entered wanted name, and ENTER, works great

有人有小费吗?要在这种情况下使此帮助有效?

Does anyone have any tip to make this assistance work under such scenarios?

推荐答案

我通常为解决for循环的内容帮助而做的事情如下:

What I usually do to solve the content assist with for loop is the following:


  • 通过输入声明在上方的集合变量和分号来创建局部变量:

  • create a local variable by typing collection variable that is declared far above and a semicolon:

list;


  • 按Ctrl + 2 L

  • press Ctrl+2 L

    Eclipse生成一个新的局部变量声明,如下所示:

    Eclipse generates a new local variable declaration which looks like this:

    List list2 = list;
    


  • 输入我的foreach并使用Ctrl + space自动完成,得到以下内容:

  • type my foreach and autocomplete with Ctrl+space getting the following:

    List list2 = list;
    for (Object object : list2) {
    }
    


  • place将光标放在for循环声明中的list2上,然后按Alt + Shift + I表示内联变量。

  • place cursor on list2 in the for loop declaration and press Alt+Shift+I which stands for inline variable.

    这将导致您想要实现。经过一些练习后,工作量很小:

    this results in what you want to achieve. The effort is minimal after some practicing:

    for (Object object : list) {
    }
    


  • 这篇关于如何获得内容辅助“ for循环”。 Eclipse中的任何地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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