简体   繁体   English

可以在赋值运算符的左侧删除自动完成吗?

[英]Can eclipse autocomplete on the left side of assignment operator?

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? 如果我输入了一个返回已知类型的表达式,那么eclipse是否有办法内容辅助创建该类型,可能还有模板化变量名称?

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> . 您会注意到,如果我将鼠标悬停在getModel()方法上,它会清楚地表明它只能返回一种类型的Map<String, Object> But if I then type Ctrl-Space with my cursor to the left of the = , nothing happens. 但是如果我然后用我的光标键入Ctrl-Space=的左边,则没有任何反应。 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. 最好是,它会创建您看到注释掉的整个Map<String, Object> modelmodel被模板化以便您可以选择它,并快速输入您的变量名称。

I suppose it's even possible that it could infer the default variable name based on the getter method name... 我想甚至有可能它可以根据getter方法名称推断默认变量名...

左侧自动完成的位置示例很有用。

You could probably use the extract variable refactoring for this use case. 您可以使用提取变量重构来实现此用例。

First type 第一种

mv.getModel()

Then go to Refactor/Extract Local Variable or just hit SHIFT + ALT + L . 然后转到Refactor / Extract Local Variable或者只需按SHIFT + ALT + L.

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. 如果有人知道更好的解决方案,请随时纠正我。

为Mac快捷:⌘2 + 1(小写L键)见: https://stackoverflow.com/a/36367780/6192949

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

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