Eclipse可以在赋值运算符的左侧自动完成吗? [英] Can eclipse autocomplete on the left side of assignment operator?

查看:140
本文介绍了Eclipse可以在赋值运算符的左侧自动完成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我键入了一个返回已知类型的表达式,是否有一种方法可以让Eclipse内容创建该类型的内容辅助(可能带有模板化变量名)?

If I have typed out an expression that returns a known type, is there a way for eclipse to content-assist the creation of that type, potentially with templated variable names?

下面的屏幕快照是一个有用的示例.您会注意到,如果将鼠标悬停在getModel()方法上,则它明确指出它只能返回单一类型的Map<String, Object>.但是,如果我然后用光标在=左侧的方式输入 Ctrl-Space ,则什么也不会发生.最好是,它将创建您看到已注释掉的整个Map<String, Object> model,并以model为模板,以便您可以选择它,并快速输入变量名.

The screenshot below is an example of where this would be useful. You'll notice that if I hover my mouse over the getModel() method, it clearly states that it can only return a single type of Map<String, Object>. But if I then type Ctrl-Space with my cursor to the left of the =, nothing happens. Preferably, it would create the whole Map<String, Object> model that you see commented out, with model being templated so you could tab to it, and quickly enter your variable name.

我想它甚至有可能根据getter方法名称来推断默认变量名称...

I suppose it's even possible that it could infer the default variable name based on the getter method name...

推荐答案

在此用例中,您可能可以使用提取变量重构.

You could probably use the extract variable refactoring for this use case.

第一种

mv.getModel()

然后转到重构/提取局部变量或直接按 SHIFT + ALT + L .

Then go to Refactor/Extract Local Variable or just hit SHIFT+ALT+L.

然后它将提示您输入变量名,然后按Enter键,您将得到:

It will then prompt you for variable name and after you hit enter you should get:

Map<String, Object> variableName = mv.getModel();

我知道问题在于内容辅助,但是据我所知不可能这样做.希望这是一个可以接受的替代方案.如果有人知道更好的解决方案,请随时纠正我.

I know that the question is about content assist, but as far as I know it isn't possible to do this that way. Hopefully this is an acceptable alternative. If someone knows a better solution feel free to correct me.

这篇关于Eclipse可以在赋值运算符的左侧自动完成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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