如何在 Eclipse java 编辑器中生成返回值类型和变量赋值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7094135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:51:04  来源:igfitidea点击:

How to generate return value type and variable assignment in Eclipse java editor?

javaeclipseeditor

提问by lisak

If I have a statement like this " EntitiesProvider.getEntities();

如果我有这样的声明“ EntitiesProvider.getEntities();

Any idea how to "generate" the assignment to variable of return Type ?

知道如何“生成”对返回类型变量的赋值吗?

so that this would be generated Map<String, Entity> hashMap =

这样就可以生成 Map<String, Entity> hashMap =

this is the result :

这是结果:

Map<String, Entity> hashMap = EntitiesProvider.getEntities();

It is similar to ctrl + 1 and Change type, if it returns different Type that you already have there.

它类似于 ctrl + 1 和 Change type,如果它返回您已经拥有的不同类型。

I find myself doing myself manually very often...

我发现自己经常手动操作...

回答by Art Licis

Ctrl+2, Lis one option, and the other is Alt+Shift+Lwhen the desired statement is selected. The popup will appear allowing to set variable name & few additional options (e.g., "Replace occurrences of the selected expression with references to the local variable").

Ctrl+2, L是一种选择,另一种Alt+Shift+L是选择所需语句时。弹出窗口将出现,允许设置变量名称和一些附加选项(例如,“用对局部变量的引用替换所选表达式的出现”)。

I prefer Alt+Shift+Lbecause it allows marking specific part of the line for variable extraction.

我更喜欢,Alt+Shift+L因为它允许标记行的特定部分以进行变量提取。

.. and here's a simple example:

.. 这是一个简单的例子:

..
new FileInputStream(new File("test.txt"));
..

You can select the whole line to assign it to FileInputStreamvariable, or you can 'extract' new File("test.txt"), or even String expression "test.txt".

您可以选择整行以将其分配给FileInputStream变量,或者您可以 'extract' new File("test.txt"),甚至 String expression "test.txt"

P.S. Sometimes I wish it would be able to let me choose supertype from combo box in a pop-up, e.g. InputStreamin this specific example.

PS 有时我希望它能够让我从弹出窗口的组合框中选择超类型,例如InputStream在这个特定示例中。

回答by Robin

CTRL=2,Lwill do what you are looking for.

CTRL=2,L会做你想要的。

回答by oliholz

What is wrong with Ctrl+2, L. With Taband /?

Ctrl+ 有什么问题2L。随着Tab/

回答by co_de_explorer

CTRL+2,L and ALT+CTRL+L can get the job done for you.

CTRL+2,L 和 ALT+CTRL+L 可以为您完成工作。

CTRL+2 is a short key to a quick assist tool which can perform

CTRL+2 是快速辅助工具的快捷键,可以执行



  1. assigning to a Field (F)
  2. assigning to a Local variable (L)
  3. extracting Method (M)
  4. Renaming in file (R)
  1. 分配给一个˚Field(F)
  2. 分配给一个大号OCAL变量(L)
  3. 提取中号ethod(M)
  4. R在文件中命名 (R)

you can press any key of these four as u need it.

您可以根据需要按这四个键中的任意键。