简体   繁体   English

在 IntelliJ 中,是否有一种快捷方式可以获取我已经输入的变量作为我想要输入的方法中的参数?

[英]In IntelliJ, is there a shortcut to get variable I've already typed to be a parameter in a method I want to type?

Suppose I have this code:假设我有这个代码:

var x = 2;
var y = x;

Then I realize that I actually wanted this:然后我意识到我实际上想要这个:

var y = someMethod(x);

To accomplish this, first I need to position the cursor to the left of "x", then type "someMethod(", then move my cursor to the right, and then add the final ")".要做到这一点,首先我需要 position cursor 到“x”的左边,然后输入“someMethod(”,然后移动我的 cursor 到右边,然后添加最后的“)。

What I'd love is to have a way to, say, highlight "x", and have it automatically get inserted as a parameter to whatever I start typing.我喜欢的是有一种方法来突出显示“x”,并让它自动作为参数插入到我开始输入的任何内容中。

Is there something for this in IntelliJ?在 IntelliJ 中有什么东西吗?

Put the cursor at the left of x , start typing the method name and wait for the autocompletion sugestions to appear (if they don't press CTRL+Space), find your method in the list, select it with keyboard arrows, and press ENTER.将 cursor 放在x的左侧,开始输入方法名称并等待自动完成提示出现(如果他们没有按 CTRL+空格键),在列表中找到您的方法 select 用键盘箭头,然后按 ENTER . IDEA will automatically use x as the parameter of the mthod. IDEA 会自动使用x作为 mthod 的参数。

Try using Statement Completion :尝试使用语句完成

  • Point the cursor before x将 cursor 指向x
  • Start typing the method name开始输入方法名称
  • Select the needed variant and press Ctrl + Shift + Enter Select 所需的变体,然后按Ctrl + Shift + Enter

暂无
暂无

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

相关问题 Intellij的方法参数完成快捷方式? - Method Parameter Completion Shortcut for Intellij? 如何为带有传递给方法的参数的catch语句设置预期的Exception类型? - How can I set the the expected Exception type for a catch statement with a parameter I've passed into a method? 当我已经声明了变量时如何修复空错误 - How to fix null error when I've already declared the variable 如果我使用快捷方式引入变量,什么是IntelliJ IDEA快捷方式声明最终变量? - What is the IntelliJ IDEA shortcut declare a final variable if I use shortcut to introduce variable? 如何获取形式化方法参数类型的参数? - How do I get the argument of the formal method parameter type? 如何获取 class 的类型以用作方法参数? - How can I get the type of a class to use as a method parameter? Eclipse快捷方式将变量名称声明为方法参数 - Eclipse shortcut to declare a variable name as method parameter 我有一个带有 1 个 setter 方法的抽象类 - 参数是一个对象。 我想要一个通用的<T>采用扩展它的类的类型的参数 - I have an abstract class w/ 1 setter method - parameter is an object. I want a generic <T> parameter that takes on the type of the class extending it 在IntelliJ中,是否可以找到具有特定类型的类型化方法的用法? - In IntelliJ, is it possible to find usages of a typed method with a specific type? Java 变量不在 scope 中,即使我已经在 class 中声明了它? - Java variable is out of scope even though I've already declared it in the class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM