如何提高 Eclipse 代码完成度?

发布于 2024-10-08 10:07:39 字数 135 浏览 6 评论 0原文

Eclipse 找不到用于代码完成的正确变量,如下所示。

int i = 0;
f(xyz);    // f takes an int but eclipse won't fill it with i.

Eclipse does not find the correct variable for code completion as shown below.

int i = 0;
f(xyz);    // f takes an int but eclipse won't fill it with i.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖个坑埋了你 2024-10-15 10:07:39

在“窗口”下> “偏好设置”> “Java”> “编辑器”> “内容辅助”,确保设置“填充方法参数并显示猜测参数”并选择“插入最佳猜测参数”。


编辑:

我在 Eclipse 中尝试了此操作(版本:Helios Service Release 1 - 构建 ID:20100917-0705):

public class BestGuessedParameter {
    static int xyz = 1;
    static void f(final int xyz) {
    }
    public static void main(final String[] args) {
        final int i = 0;
        f/*cursor here*/
    }
}

在输入 f 后,我按空格并选择f(xyz),Eclipse 确实提供了 f(i),其中 i 突出显示,并且在 i 的下拉菜单中code>(突出显示)、xyz0i 是默认值。

我找不到任何关于 Eclipse 如何选择“最佳猜测参数”的信息(我不知道在 Eclipse 源代码中查找)。我猜测 Eclipse 会根据类型、名称和可见性进行“猜测”,并且 Eclipse 认为存在比本地变量更好的匹配。也许如果局部变量的类型和名称更接近,它会是更好的匹配?

Under "Window" > "Preferences" > "Java" > "Editor" > "Content Assist", make sure "Fill method arguments and show guess arguments" is set and "Insert best guessed arguments" is selected.


Edit:

I tried this in my Eclipse (Version: Helios Service Release 1 - Build id: 20100917-0705):

public class BestGuessedParameter {
    static int xyz = 1;
    static void f(final int xyz) {
    }
    public static void main(final String[] args) {
        final int i = 0;
        f/*cursor here*/
    }
}

Right after I typed the f, I hit space and selected f(xyz), Eclipse did supply f(i) with i highlighted and in a pop-down menu of i (highlighted), xyz, and 0. i was the default.

I couldn't find any info on how Eclipse selects the "best guessed parameters" (I have no idea where to look in the Eclipse source). I would guess that Eclipse "guesses" based on type, name, and visibility, and that Eclipse thinks there's a better match than your local variable. Perhaps if the local variable were closer in type and name, it would be a better match?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文